CentOS 7上安装MySQL-8.0.16

mysql8 安装
https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.16-linux-glibc2.12-x86_64.tar

1.卸载mariadb
[root@node2 ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
[root@node2 ~]# rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64


2.创建mysql账号
配置mysql
新建mysql用户、组及目录
---新建一个msyql组
groupadd mysql
新建msyql用户禁止登录shell
useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql
或者useradd -g mysql mysql

3.解压mysql包
[root@node2 tools]# tar -xvf mysql-8.0.16-linux-glibc2.12-x86_64.tar
[root@node2 tools]# cd /usr/local/
[root@node2 local]# tar -Jxf /usr/tools/mysql-8.0.16-linux-glibc2.12-x86_64.tar.xz
[root@node2 local]# mv mysql-8.0.16-linux-glibc2.12-x86_64/ mysql
将mysql用户加入到mysql用户组
[root@node2 ~]# chown -R mysql:mysql /usr/local/mysql


4.创建data目录并赋权限
[root@node2 ~]# chmod -R 777 /usr/local/mysql/data
[root@node2 ~]# chmod -R 777 /usr/local/mysql/
[root@node2 ~]# chmod -R 777 /usr/local/mysql/data/

5.创建配置文件
[root@node2 mysql]# vi /etc/my.cnf

[mysqld]
port=3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
max_connections=10000
max_connect_errors=10
character-set-server=utf8
default-storage-engine=INNODB
default_authentication_plugin=mysql_native_password
[mysql]
default-character-set=utf8
[client]
port=3306
default-character-set=utf8
[mysqld_safe]
log-error=/usr/local/mysql/log/mysql.log
pid-file=/usr/local/mysql/data/mysql.pid

6.初始化mysql:执行mysqld,并保存临时密码
[root@node2 mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/mysql.pid --explicit_defaults_for_timestamp
2019-05-29T18:35:26.538754Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.16) initializing of server in progress as process 9293
2019-05-29T18:35:26.540636Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2019-05-29T18:35:29.344260Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: R()jftx5B+sy
2019-05-29T18:35:30.702045Z 0 [System] [MY-013170] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.16) initializing of server has completed


7.启动mysql
[root@node2 local]# cd mysql/support-files/
[root@node2 support-files]# ./mysql.server start
Starting MySQL.Logging to '/usr/local/mysql/data/node2.test.com.err'.
ERROR! The server quit without updating PID file (/usr/local/mysql/data/node2.test.com.pid).

查看错误log
[root@node2 support-files]# cat /usr/local/mysql/data/node2.test.com.err
2019-05-29T05:30:04.370448Z 0 [System] [MY-010116] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.16) starting as process 15239
2019-05-29T05:30:04.372719Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2019-05-29T05:30:04.380446Z 1 [ERROR] [MY-011011] [Server] Failed to find valid data directory.
2019-05-29T05:30:04.380526Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2019-05-29T05:30:04.380590Z 0 [ERROR] [MY-010119] [Server] Aborting
2019-05-29T05:30:04.381248Z 0 [System] [MY-010910] [Server] /usr/local/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.16) MySQL Community Server - GPL.

可能是对data目录没权限
chmode -R 777 /usr/local/mysql/data
我这次的原因是没有对mysql进行初始化


8.设置开启启动mysql
将support-file中的mysql.server复制到init.d下
cp mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld

修改/etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data

9.启动mysql
[root@node2 mysql]# service mysqld start
Starting MySQL SUCCESS!

10.把mysql加入环境变量
vi /etc/profile
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin

source /etc/profile


11.mysql设置,密码为第6步的临时密码
[root@node2 mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.16

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

12.修改root密码,设置远程访问
mysql> alter user "root"@"localhost" identified by "root";
mysql> create user root@'%' identified by 'root';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on*.* to root with grant option;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

 

posted on 2019-05-30 16:13  爬山虎hu  阅读(345)  评论(0编辑  收藏  举报