linux安装mysql8

记录,关于mysql8.0.11的安装。

系统版本:Linux version 3.10.0-862.14.4.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-28)

MySQL版本:8.0.11(注意官网新版的mysql后缀是xz,不是gz了。下载时,根据系统位数。64还是32)

我是在本机下载的,通过WinSCP上传到服务器,目录是  /usr/local/

相关注意事项:

mysql5.7后,user表没有password字段,换成authentication_string。

1.先看看系统里有没有mysql需要的库。如numactl,libaio。

命令格式如下:

rpm -qa | grep 名称

例如:

rpm -qa | grep numactl。



示范:

[root@Airflite_db01 ~]# rpm -qa | grep numactl

numactl-libs-2.0.9-7.el7.x86_64

[root@Airflite_db01 ~]# rpm -qa | grep libaio

libaio-0.3.109-13.el7.x86_64

有结果证明是存在的。

2.进入/usr/local/  这里是你上传mysql的地方

[root@Airflite_db01 ~]# cd /usr/local/

 

3.进行解压。你的mysql名称不一定和我一样。输入tar -zxvf mysql(按下Tab),会自动补全。

[root@Airflite_db01 local]# tar -zxvf mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz

 

4.把解压出来的文件,移动到 /user/local/mysql里,(不确定有没有解压出来可以到WinSCP连接看看,不用特地去创建mysql这个文件)

[root@Airflite_db01 local]# mv mysql-8.0.11-linux-glibc2.12-x86_64 /usr/local/mysql

5.添加必要的用户组等等

[root@Airflite_db01 local]# groupadd mysql

[root@Airflite_db01 local]# useradd -r -g mysql -s /bin/false mysql

[root@Airflite_db01 local]# cd mysql

[root@Airflite_db01 mysql]# mkdir mysql-files

[root@Airflite_db01 mysql]# chown mysql:mysql mysql-files

[root@Airflite_db01 mysql]# chmod 750 mysql-files

6.接下来要初始化mysql,这一步大多会出错,原因有千千万。

[root@Airflite_db01 mysql]# bin/mysqld --initialize --user=mysql

 

结果:

mysqld: Can't change dir to '/usr/local/mysql/data/' (OS errno 13 - Permission denied)

2018-10-19T07:40:14.595834Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.11) initializing of server in progress as process 141149

2018-10-19T07:40:14.598768Z 0 [ERROR] [MY-010172] [Server] failed to set datadir to /usr/local/mysql/data/

2018-10-19T07:40:14.598788Z 0 [ERROR] [MY-010119] [Server] Aborting

2018-10-19T07:40:14.598943Z 0 [System] [MY-010910] [Server] /usr/local/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.11)  MySQL Community Server - GPL.

 

好吧,Permission denied。还好还好,问题不大,只是没权限,给加上就行了。

解决:(777  clearlove发功啦)

[root@Airflite_db01 mysql]# chmod 777 /usr/local/mysql

 

再次初始化:

[root@Airflite_db01 mysql]# bin/mysqld --initialize --user=mysql

2018-10-19T07:42:27.756076Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.11) initializing of server in progress as process 141312

2018-10-19T07:42:31.700578Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: L:ojzrgch5qe

2018-10-19T07:42:34.127673Z 0 [System] [MY-013170] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.11) initializing of server has completed

 

诶,这就很舒服了。root@localhost: L:ojzrgch5qe。L:ojzrgch5qe 是root初始的密码。(注意localhost: 和 L中间有个空格是不归入密码的。)

7.复制服务文件:

[root@Airflite_db01 mysql]# cp support-files/mysql.server /etc/init.d/mysql.server

 

8.启动服务:(如果卡住了,就再按一下回车。)

[root@Airflite_db01 mysql]# bin/mysqld_safe --user=mysql &

 

9.修改root的密码,以及远程权限。

[root@Airflite_db01 mysql]# bin/mysql -uroot -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 8

Server version: 8.0.11



Copyright (c) 2000, 2018, 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.



mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '密码' PASSWORD EXPIRE NEVER;

Query OK, 0 rows affected (0.07 sec)





mysql> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A



Database changed

mysql> update user set host='%' where user = 'root';

Query OK, 1 row affected (0.09 sec)

Rows matched: 1  Changed: 1  Warnings: 0



mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '密码';

Query OK, 0 rows affected (0.07 sec)



mysql> flush privileges;

Query OK, 0 rows affected (0.01 sec)



mysql> exit;

可以在本机用navicat连接试试。

关于mysql_native_password,这个密码策略。如果要搞主从复制,创建用户时,也需要设置密码策略。

你可能感兴趣的:(linux,mysql)