centos7通过Yum安装mysql8
2019-12-03centos7安装mysql8包越来越大,编译安装和通过tar包安装都需要几个G空间,yum安装过程相对来说占用空间少一些。
1、安装mysql80-community-release.noarch
wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
yum -y localinstall mysql80-community-release-el7-1.noarch.rpm
2、yum search mysql-community-server
yum -y install mysql-community-server
Dependencies Resolved
Installing: mysql-community-libs x86_64 8.0.18-1.el7 mysql80-community 3.7 M
replacing mariadb-libs.x86_64 1:5.5.64-1.el7
mysql-community-libs-compat x86_64 8.0.18-1.el7 mysql80-community 1.3 M
replacing mariadb-libs.x86_64 1:5.5.64-1.el7
mysql-community-server x86_64 8.0.18-1.el7 mysql80-community 429 M
Installing for dependencies:
mysql-community-client x86_64 8.0.18-1.el7 mysql80-community 38 M
mysql-community-common x86_64 8.0.18-1.el7 mysql80-community 597 k
3、mysql8临时密码存放在/var/log/mysqld.log里面
但是包含特殊字符,总是提示错误密码。
4、mysql8重置密码
修改/etc/my.cnf增加
skip-grant-tables
update user set authentication_string='' where user='root' ;
systemctl restart mysqld
无密码登陆mysql
alter user 'root'@'localhost' identified by 'J8sl4zj>r+w';
5、设置MYSQL_PWD变量来避免输出Warning信息
export MYSQL_PWD=mysql_password
mysql -uroot -Dmysql -e 'select user from user;'
6、增加db和user
#!/bin/sh
#mysql -uroot -e"drop user 'root'@'`hostname`'"
#mysql -uroot
export MYSQL_PWD=123456
#mysql -uroot -e"create database mndb;"
#mysql -uroot -e"CREATE USER 'mnuser'@'localhost' IDENTIFIED BY 'l';"
#mysql -uroot -e"alter USER 'medallionuser'@'localhost' IDENTIFIED WITH mysql_native_password BY 'l';"
mysql -uroot -e"GRANT ALL privileges ON mndb.* TO 'mnuser'@'localhost';"
mysql -uroot -e"flush privileges;"
mysql -uroot -e"commit;"
ALTER USER 'test'@'%' IDENTIFIED WITH mysql_native_password BY '111111';