在亚马逊Red Hat 7.1 linux上安装mysql
安装前检查之前是否安装并卸载之前的和删除关联文件
rpm -qa|grep mysql
yum remove mysql mysql-server mysql-libs mysql-common //在线删除
rpm -e mysql57-community-release-el7-9.noarch // 普通删除模式
rm -rf /var/lib/mysql
rm /etc/my.cnf
软件卸载完毕后如果需要可以删除mysql的数据库:rm -rf /var/lib/mysql
在线安装方式
1.一开始是通过这个命令来直接安装的:
yum install mysql mysql-server mysql-devel
提示:
安装mysql和mysql-devel都成功,但是安装mysql-server失败
解决方式:
第一种:用*MariaDB*来代替
第二种:就是从官网上下载安装
wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm //下载YUM库
yum localinstall -y mysql57-community-release-el7-7.noarch.rpm //安装YUM库
yum install -y mysql-community-server //安装数据库
2.service mysqld start //启动数据库服务
3.mysql -uroot -p //默认空密码
提示:
解决方法:
请修改my.cnf,添加skip-grant-tables和skip-networking:
请修改my.cnf,添加skip-grant-tables和skip-networking:
vi /etc/my.cnf
[mysqld]
skip-grant-tables
skip-networking
4.重启服务器
service mysqld restart
这样就能登录了
mysql -uroot -p //默认空密码
5.重置root密码后再重启mysql服务:修改成功
mysql>update mysql.user set authentication_string=password("yourpassword") where user="root" and Host="localhost”;
mysql>flush privileges;
mysql>quit;
service mysqld restart
6.记得密码修改完后,去掉my.cnf添加的两行
# mysql -uroot -p 123
mysql> SHOW DATABASES
提示:
You must reset your password using ALTER USER statement before executing this statement.
7.修改数据库密码
mysql> alter user 'root'@'localhost' identified by 'root';
提示:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
原因:
MySQL5.6.6版本之后增加了密码强度验证插件validate_password,相关参数设置的较为严格。
使用了该插件会检查设置的密码是否符合当前设置的强度规则,若不满足则拒绝设置。影响的语句和函数有:create user,grant,set password,password(),old password。
解决方法:
1) 查看一下msyql密码相关的几个全局参数:
mysql> select @@validate_password_policy;
+----------------------------+
| @@validate_password_policy |
+----------------------------+
| MEDIUM |
+----------------------------+
1 row in set (0.00 sec)
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| 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 |
+--------------------------------------+--------+
6 rows in set (0.08 sec)
2)参数解释
validate_password_dictionary_file
插件用于验证密码强度的字典文件路径。
validate_password_length
密码最小长度,参数默认为8,它有最小值的限制,最小值为:validate_password_number_count + validate_password_special_char_count + (2 * validate_password_mixed_case_count)
validate_password_mixed_case_count
密码至少要包含的小写字母个数和大写字母个数。
validate_password_number_count
密码至少要包含的数字个数。
validate_password_policy
密码强度检查等级,0/LOW、1/MEDIUM、2/STRONG。有以下取值:
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,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。
validate_password_special_char_count
密码至少要包含的特殊字符数。
3)修改mysql参数配置
[sql] view plain copy
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.05 sec)
mysql>
mysql>
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)
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password_dictionary_file | |
| validate_password_length | 3 |
| validate_password_mixed_case_count | 0 |
| validate_password_number_count | 3 |
| validate_password_policy | LOW |
| validate_password_special_char_count | 0 |
+--------------------------------------+-------+
6 rows in set (0.00 sec)
8.通过 Sequel Pro连接数据库时
1.ssh方式连接
提示:
MySQL said: Can't connect to MySQL server on 'ec2-13-112-210-143.ap-northeast-1.compute.amazonaws.com' (4)
解决方法:
1。 改表法。可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称”%"
mysql -u root -p123
mysql>use mysql;
mysql>update user set host = '%' where user = 'root’;
mysql>select host, user from user;
2. 授权法。例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
如果你想允许用户myuser从ip为192.168.1.3的主机连接到mysql服务器,并使用mypassword作为密码
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY
'mypassword' WITH GRANT OPTION;
2.Standard连接方式
提示:
MySQL said: Can't connect to MySQL server on 'ec2-13-112-210-143.ap-northeast-1.compute.amazonaws.com' (4)
解决方式同上
你投入得越多,就能得到越多得价值