准备环境:
关闭防火墙
关闭selinux
帮助文档:快速安装MySQL
安装常用工具:
[root@localhost ~]# yum install -y vim tree wget
下载rpm:
[root@localhost ~]# wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
安装yum源:
[root@localhost ~]# yum install -y mysql80-community-release-el7-1.noarch.rpm
安装mysql:
[root@localhost ~]# yum install -y mysql-community-server
启动mysql:
[root@localhost ~]# systemctl start mysqld.service
检查mysql启动状态:
[root@localhost ~]# systemctl status mysqld.service
配置mysql开机自启动:
[root@localhost ~]# systemctl enable mysqld.service
第一次登录,获取mysql的root用户初始化密码:
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
修改mysql的root用户的密码:
[root@localhost ~]# mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
常见问题:
1、ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
需要使用ALTER USER修改密码。
2、ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
密码的复杂度不符合要求。
密码策略:
MySQL's validate_password plugin is installed by default. This will require that passwords contain at least one upper case letter, one lower case letter, one digit, and one special character, and that the total password length is at least 8 characters.
yum安装的默认密码策略:至少包含一个大写字符、一个小写字符、一个数字、一个特殊字符,并且密码总长度至少是8个字符。
添加用户:
[root@localhost ~]# mysql -uroot -p
mysql> use mysql;
mysql> CREATE USER '用户名'@'%' IDENTIFIED BY '密码';
mysql> grant all on 数据库名称.* to 'salt'@'%';
mysql> exit;