mysql 安装

Posted 薛定谔的猫!

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql 安装相关的知识,希望对你有一定的参考价值。

这里使用的mysql是 mysql-5.7.16

将下载下来的mysql 安装tar包下载解压这就不用多说了,

 ps:(mysql-5.7.16-linux-glibc2.5-x86_64 这名字太长了,我把他改为mysql-5.7.16)

首先

(1)配置环境变量

############mysql#############
export PATH=$PATH:/usr/local/development/mysql/mysql-5.7.16/bin

(2)新增mysql的用户和组

[root@node1 development]# groupadd mysql
[root@node1 development]# useradd -r -g mysql mysql
//修改mysql的目录权限 [root@node1 development]# chown -R mysql mysql /usr/local/development/mysql/mysql-5.7.16/

(3)修改mysql安装目录中的   support-files/mysql.server 文件,设置mysql的安装目录 和 mysql的数据存储目录

# If you want to affect other MySQL variables, you should make your changes
# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.

# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.
//mysql的安装目录
basedir=/usr/local/development/mysql/mysql-5.7.16
//mysql的数据存储目录 datadir=/usr/local/development/mysql/mysqlData

(4)初始化数据库

[root@node1 bin]# ./mysql_install_db --user=mysql --basedir=/usr/local/development/mysql/mysql-5.7.16 --datadir=/usr/local/development/mysql/mysqlData
2017-06-05 17:44:50 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize 2017-06-05 17:44:55 [WARNING] The bootstrap log isn\'t empty: 2017-06-05 17:44:55 [WARNING] 2017-06-05T09:44:51.057443Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead 2017-06-05T09:44:51.075095Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000) 2017-06-05T09:44:51.075137Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)

我们的MySQL存储目录已经生成数据了

(5)启动MySQL(发现报错)

[root@node1 support-files]# ./mysql.server start
Starting MySQL.touch: cannot touch ‘/var/log/mariadb/mariadb.log’: No such file or directory
chmod: cannot access ‘/var/log/mariadb/mariadb.log’: No such file or directory
touch: cannot touch ‘/var/log/mariadb/mariadb.log’: No such file or directory
chown: cannot access ‘/var/log/mariadb/mariadb.log’: No such file or directory
/usr/local/development/mysql/mysql-5.7.16/bin/mysqld_safe: line 135: /var/log/mariadb/mariadb.log: No such file or directory
/usr/local/development/mysql/mysql-5.7.16/bin/mysqld_safe: line 169: /var/log/mariadb/mariadb.log: No such file or directory
touch: cannot touch ‘/var/log/mariadb/mariadb.log’: No such file or directory
chown: cannot access ‘/var/log/mariadb/mariadb.log’: No such file or directory
chmod: cannot access ‘/var/log/mariadb/mariadb.log’: No such file or directory
/usr/local/development/mysql/mysql-5.7.16/bin/mysqld_safe: line 135: /var/log/mariadb/mariadb.log: No such file or directory
 ERROR! The server quit without updating PID file (/usr/local/development/mysql/mysqlData/node1.pid).

我们确实是没有/var/log/mariadb/mariadb.log 这个目录,这个是因为你没有指定他的配置文件的话,他会默认找到/etc/my.cnf 这个配置文件,因为我们修改了mysql的数据存储目录。

将/etc/my.cnf 删掉,再次启动

[root@node1 support-files]# rm -f /etc/my.cnf
[root@node1 support-files]# ./mysql.server start
Starting MySQL.. SUCCESS! 

(6)查询MySQL自动生成的root密码

[root@node1 support-files]# more /root/.mysql_secret 
# Password set for user \'root@localhost\' at 2017-06-05 17:44:50 
N5*gFyur1LbC                          //这里就是

(7)在bin目录下 登录MySQL(将自动生成的密码粘贴上去即可)

[root@node1 bin]# ./mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \\g.
Your MySQL connection id is 2
Server version: 5.7.16

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type \'help;\' or \'\\h\' for help. Type \'\\c\' to clear the current input statement.

(8)修改MySQL的root密码(你肯定不想使用自动生成的那个密码吧)

mysql> set password=password(\'mysql123\');//设置密码
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> alter user \'root\'@\'localhost\' password expire never//将密码应用于root用户
    -> ;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges//刷新权限的列表
    -> ;
Query OK, 0 rows affected (0.00 sec)

mysql> exit//退出
Bye

重新登录,试一试刚才修改的密码是否生效,当然你们是看不见输入密码的,我这里已经生效了

上面是MySQL的搭建过程,我是使用MySQL来存储hive的元数据,而MySQL不允许使用root用户远程登录,所以我新建hive用户

mysql> create user \'hive\'@\'%\' identified by \'hive123\';//创建用户名和密码
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on *.* to \'hive\'@\'%\';//赋予hive用户所有权限,\'%\'表示任何地址都可以通过hive用户连接mysql,如果你想限制可以加入你的ip
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;//刷新权限列表
Query OK, 0 rows affected (0.00 sec)

mysql> create database hivedb;//创建数据库
Query OK, 1 row affected (0.00 sec)

查看创建的数据库

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| hivedb             |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

 

以上是关于mysql 安装的主要内容,如果未能解决你的问题,请参考以下文章

从mysql的片段中加载ListView

连接MySQL出现错误:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)(代码片段

使用 json rereiver php mysql 在片段中填充列表视图

在Tomcat的安装目录下conf目录下的server.xml文件中增加一个xml代码片段,该代码片段中每个属性的含义与用途

PHP代码-psysh调试代码片段工具

关于mysql驱动版本报错解决,Cause: com.mysql.jdbc.exceptions.jdbc4Unknown system variable ‘query_cache_size(代码片段