环境:mysql
1、Yum安装MySQLsql
1.下载yum库shell
shell > wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
2.安装yum库数据库
shell > yum localinstall -y mysql57-community-release-el7-7.noarch.rpm
3.安装数据库安全
shell > yum install -y mysql-community-server
4.启动MySQL服务bash
shell > systemctl start mysqld.service #启动 shell > systemctl stop mysqld.service #中止 shell > systemctl restart mysqld.service #重启
5.注意:MySQL5.7安装后会有一个默认生成的root密码,咱们要获取到这个密码,经过下面这个命令就能够获取到随机生成的root密码服务器
shell > sudo grep 'temporary password' /var/log/mysqld.log
6.使用随机生成的密码进入mysqlide
shell > mysql -uroot -p shell > Enter password:
7.使用随机生成的密码进入到mysql,必须立刻修改密码,否则会出现以下错误ui
mysql> select user(); ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
8. 若是只是修改成一个简单的密码,会报如下错误:this
mysql> ALTER USER USER() IDENTIFIED BY 'root'; ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
这是由于MySQL5.7默认安装了validate_password插件,用来校验设置密码是否符合必定要求,以保证密码的安全性。请查看第二部分以后,再修改密码;
2、MySQL5.7的validate_password插件
1. validate_password_policy 密码校验策略,这个密码校验策略就会校验你设置的密码是否符合当前MySQL校验策略的要求。
有以下策略:
Policy | Tests Performed |
0 or LOW | Length |
1 or MEDIUM | Length; numeric, lowercase/uppercase, and special characters |
2 or STRONG | Length; numeric, lowercase/uppercase, and special characters; dictionary file |
策略:默认是1,即MEDIUM,因此刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。
实例:可是有时候,不想密码设置得那么复杂,好比我只想设置root的密码为root。
(1)首先,咱们要将validate_password_policy 策略修改成0,即只校验密码长度:
mysql> set global validate_password_policy=0; Query OK, 0 rows affected (0.00 sec)
(2)此时,就由validate_password_length参数来判断了,即判断密码的长度便可,咱们先看看此时咱们validate_password_length的要求是什么:
select @@validate_password_length; +----------------------------+ | @@validate_password_length | +----------------------------+ | 8 | +----------------------------+ 1 row in set (0.00 sec)
注意: validate_password_length参数默认为8,它有最小值的限制,最小值为:
validate_password_number_count + validate_password_special_char_count + (2 * validate_password_mixed_case_count)
上面参数解析:
mysql> select @@validate_password_length; +----------------------------+ | @@validate_password_length | +----------------------------+ | 8 | +----------------------------+ 1 row in set (0.00 sec) mysql> set global validate_password_length=1; Query OK, 0 rows affected (0.00 sec) mysql> select @@validate_password_length; +----------------------------+ | @@validate_password_length | +----------------------------+ | 4 | +----------------------------+ 1 row in set (0.00 sec)
注意:若是修改了
validate_password_number_count,validate_password_special_char_count,validate_password_mixed_case_count中任何一个值,则validate_password_length将进行动态修改。以下,我将
validate_password_mixed_case_count的值修改为2,则validate_password_length就会动态修改为6。
mysql> select @@validate_password_length; +----------------------------+ | @@validate_password_length | +----------------------------+ | 4 | +----------------------------+ 1 row in set (0.00 sec) mysql> select @@validate_password_mixed_case_count; +--------------------------------------+ | @@validate_password_mixed_case_count | +--------------------------------------+ | 1 | +--------------------------------------+ 1 row in set (0.00 sec) mysql> set global validate_password_mixed_case_count=2; Query OK, 0 rows affected (0.00 sec) mysql> select @@validate_password_mixed_case_count; +--------------------------------------+ | @@validate_password_mixed_case_count | +--------------------------------------+ | 2 | +--------------------------------------+ 1 row in set (0.00 sec) mysql> select @@validate_password_length; +----------------------------+ | @@validate_password_length | +----------------------------+ | 6 | +----------------------------+ 1 row in set (0.00 sec)
3、常见错误解决办法
1.ERROR 1290 (HY000): The MySQL server is running with the –skip-grant-tables option so it cannot execute this statement.
解决办法:
shell> mysql mysql> set global read_only=0; mysql> flush privileges; mysql> quit shell> /usr/bin/mysql_secure_installation
2.[ERROR] InnoDB: Cannot create log files because data files are corrupt or the database was not shut down cleanly after creating the data files.
解决办法:
shell> cd /var/lib/mysql shell> mv ibdata1 ibdata1.bak
3.[ERROR] InnoDB: space header page consists of zero bytes in data file ./ibdata1
解决办法:
innodb_flush_log_at_trx_commit = 2 在此后添加下面内容 innodb_flush_method=normal
4.ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)
解决办法:没有输入密码,注意MySQL5.7默认初始密码不为空,会产生一个随机密码!
临时密码获取:sudo grep 'temporary password' /var/log/mysqld.log
5.ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)
解决办法:密码错误,请检查后从新输入!
4、远程访问MySQL须要的配置
1.首先,在云服务安全组配置安全规则,开放MySQL的3306端口
2.查看3306端口是否开放,并绑定内网IP
#netstat -anpt | grep 3306 修改 /etc/my.cnf # vi /etc/my.cnf ---->bind-address = 内网IP(10.141.26.176)
3.给root用户全部的mysql操做权限
mysql > grant all privileges on *.* to root @"%" identified by "root" with grant option; mysql > flush privileges;
4.关闭服务器防火墙
开启 start 关闭 stop 当前状态 status 重启 restart 开机启动禁止 disable 开机自启动 enable shell > systemctl start firewalld.service 其余服务:httpd.service
以上,你就能够在本机的mysql图像化界面去链接你的云服务中安装的MySQL了!
本文为原创文章,若是对你有一点点的帮助,别忘了点赞哦!比心!如需转载,请注明出处,谢谢!