安装MySQL5.7
CentOS7的yum源中默认是mariadb,没有mysql的。为了解决这个问题,可以通过以下三种方法:
1.通过yum命令在线安装;
2.下载离线rpm安装包安装;
3.下载源码编译安装
今天介绍第一种方法,也是最方便的:
1.下载mysql的repo源
[root@localhost local]# wget https://repo.mysql.com//mysql57-community-release-el7-9.noarch.rpm
2.安装下载的rpm包
[root@localhost local]# rpm mysql57-community-release-el7-9.noarch.rpm
3.yum安装mysql
[root@localhost local]# yum install mysql-server
4.启动mysql
[root@localhost local]# service mysqld start
或者
[root@localhost local]# systemctl start mysqld.service
*小笔记*
mysql 启动、重启、停止
1.第一种
systemctl start mysqld.service
systemctl restart mysqld.service
systemctl stop mysqld.service
2.第二种
service mysqld start
service mysqld restart
service mysqld stop
修改初始root密码
mysql5.7.6以后的版本在启动数据库的时候,会生成密码放到日志文件里,可从从日志获取:
[root@localhost local]# cat /var/log/mysqld.log | grep 'password'
2017-02-08T10:48:53.368640Z 1 [Note] A temporary password is generated for root@localhost: lRym!ofXx6/r
日志的第一条最后那串字符就是初始密码,这里是 lRym!ofXx6/r
使用该密码登录即可
[root@localhost local]# mysql -uroot -p
Enter password:
登录后输入sql语句发现
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
意思是要修改初始密码,修改方法如下(这里密码是Xm123456@):
mysql> set password='Xm123456@';
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
用新密码重新登录即可,测试可以执行sql语句了,到此修改初始root密码完成。
*为什么设置初始密码一定要有字母有数字和特殊字符啥的*
因为mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。
否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误。
默认要求通过如下命令查看:
mysql> show variables like 'vali%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 8 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | MEDIUM |
| validate_password_special_char_count | 1 |
+--------------------------------------+--------+
7 rows in set (0.01 sec)
网友评论