CentOS安装MySQL
2018-09-30 本文已影响21人
ChangLau
通过Yum安装Mysql
Step1: 检测系统是否自带安装mysql
# yum list installed | grep mysql
Step2: 删除系统自带的mysql及其依赖
# yum -y remove mysql-libs.x86_64
Step3: 给CentOS添加rpm源,并且选择较新的源
# wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
# yum localinstall mysql-community-release-el6-5.noarch.rpm
# yum repolist all | grep mysql
# yum-config-manager --disable mysql55-community
# yum-config-manager --disable mysql56-community
# yum-config-manager --enable mysql57-community-dmr
# yum repolist enabled | grep mysql
Step4:安装mysql 服务器
# yum install mysql-community-server
Step5: 启动mysql
# service mysqld start
Step6: 查看mysql是否自启动,并且设置开启自启动
# chkconfig --list | grep mysqld
# chkconfig mysqld on
Step7:获取MySQL的临时密码
为了加强安全性,MySQL5.7为root用户随机生成了一个密码,在error log中,关于error log的位置,如果安装的是RPM包,则默认是/var/log/mysqld.log。只有启动过一次mysql才可以查看临时密码
cat /var/log/mysqld.log
8:登陆并修改密码
使用默认的密码登陆
mysql -uroot -p
9:修改密码复杂度
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.05 sec)
mysql> set global validate_password_mixed_case_count=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_number_count=3;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_special_char_count=0;Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=3;
Query OK, 0 rows affected (0.00 sec)
再次执行修改密码就可以了(默认密码等级高不能设置简单密码故作此设置)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123';
10.授权其他机器登陆
mysql> update user set host = '%' where user = 'root';
mysql> flush privileges;
把缓存flush掉,在使用update语句修改用户记录后,需要FLUSH语句告诉服务器重载授权表。