Centos7安装mysql8.0

创建Mysql账户

groupadd mysql
useradd -g mysql mysql

准备安装包

mysql-community-common-8.0.11-1.el7.x86_64.rpm 
mysql-community-libs-8.0.11-1.el7.x86_64.rpm
mysql-community-client-8.0.11-1.el7.x86_64.rpm 
mysql-community-server-8.0.11-1.el7.x86_64.rpm

安装Mysql

rpm -ivh mysql-community-common-8.0.11-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.11-1.el7.x86_64.rpm 
rpm -ivh mysql-community-client-8.0.11-1.el7.x86_64.rpm 
rpm -ivh mysql-community-server-8.0.11-1.el7.x86_64.rpm

报错1
	error: Failed dependencies:
		/usr/bin/perl is needed by mysql-community-server-8.0.11-1.el7.x86_64
		perl(Getopt::Long) is needed by mysql-community-server-8.0.11-1.el7.x86_64
		perl(strict) is needed by mysql-community-server-8.0.11-1.el7.x86_64
解决1
	yum install perl
	
报错2
	error: Failed dependencies:
        libaio.so.1()(64bit) is needed by mysql-community-server-8.0.11-1.el7.x86_64
        libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-8.0.11-1.el7.x86_64
        libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-8.0.11-1.el7.x86_64
 解决2
 	wget http://mirror.centos.org/centos/6/os/x86_64/Packages/libaio-0.3.107-10.el6.x86_64.rpm
 	rpm -ivh http://mirror.centos.org/centos/6/os/x86_64/Packages/libaio-0.3.107-10.el6.x86_64.rpm

初始化

mysqld --initialize

启动数据库

systemctl start mysqld

报错1
	Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.

	mysqld.service - MySQL Server
	Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
	Active: failed (Result: exit-code) since Sat 2020-05-16 22:32:41 EDT; 1min 11s ago
		Docs: man:mysqld(8)
			http://dev.mysql.com/doc/refman/en/using-systemd.html
	Process: 1979 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS (code=exited, status=1/FAILURE)
	Process: 1962 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
	Main PID: 1979 (code=exited, status=1/FAILURE)
	Status: "SERVER_BOOTING"
		Error: 2 (No such file or directory)

解决1
	rm -rf /var/lib/mysql
	service mysqld restart

查看初始化密码

vim /var/log/mysqld.log
;%WTMdmz0b#a
A temporary password is generated for root@localhost: 9-RPh%iolxz*

报错1
	Access denied for user 'root'@'localhost' (using password: YES)
解决1
	vim /etc/my.cnf

	default-authentication-plugin=mysql_native_password #配置文件本来就有去掉注释即可
	symbolic-links=0	

	重启mysql服务

链接Mysql

mysql -uroot -p
密码为上一步找到的初始化密码

重置密码

--设置复杂程度
set global validate_password.policy=0;

--设置密码长度
set global validate_password.length=6;

ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

开启远程连接权限

CREATE USER 'root'@'%' IDENTIFIED BY '123456';
grant all on *.* to 'root'@'%';
flush PRIVILEGES; 

连接报错

Navicat 连接1251 因为mysql8.0改变了加密方式,使用下面的命令即可解决问题
ALTER USER 'root'@'%' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
FLUSH PRIVILEGES;

启停命令

systemctl start mysqld.service
systemctl status mysqld.service
systemctl enable mysqld.service
systemctl restart mysqld
上一篇:分库分表数据库中间件对比


下一篇:安装及管理程序