wget http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm
注:minimal版本如果报下面错误
解决办法:安装wget
yum install wget
sudo rpm -ivh mysql57-community-release-el7-10.noarch.rpm
sudo yum -y install mysql-community-server
systemctl start mysqld.service
systemctl status mysqld.service
1、查看初始密码(使用root用户操作)
# grep "password" /var/log/mysqld.log
2、使用初始密码登录
# mysql -uroot -p
3、修改密码,mysql强制用户必须修改密码,不然只能登陆,却不能操作数据库(注意:在修改密码时密码复杂度不能太简单,如:123456,但是我们自己开发时又不想设置的太复杂,所以在修改密码之前先修改密码复杂度,如若不想修改密码复杂度,请直接执行ALTER语句)
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)
4、修改默认字符集,mysql默认的database和server字符集为latin1,我们需要把它修改为utf8
mysql> show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.01 sec)
mysql> set character_set_database=utf8;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> set character_set_server=utf8;
Query OK, 0 rows affected (0.00 sec)
mysql>
5、授权root用户可以从任意主机登录(注意将123456换成自己的密码)
mysql> grant all privileges on *.* to root@"%" identified by "123456" with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>
注:"%"表示匹配全部,可以换做主机名(ip也行),换做主机名的话,就是指定主机访问本机的mysql
grant:授权
all:所有权限
*.*:数据库名称.表名称
root:操作mysql的用户
@'':主机名
密码:123456
6、刷新或者退出并重启mysql
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
如果使用退出并重启mysql如下(exit和quit都可以退出)
mysql> quit
Bye
[root@hadoop1 conf]# systemctl restart mysqld.service
[root@hadoop1 conf]#
7、开放3306(mysql默认的端口)
[root@hadoop1 conf]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@hadoop1 conf]# firewall-cmd --reload
success
[root@hadoop1 conf]#
执行完以上步骤还是不能远程连接mysql的话,尝试开放防火墙的3306端口或者关闭防火墙
8、可以删除mysql57-community-release-el7-10.noarch.rpm,也可以不删除,(如果找不到了,可以使用find等查找命令)
1、列出所有被安装的rpm package
# rpm -qa | grep mariadb
mariadb-libs-5.5.50-1.el7_2.x86_64
mariadb-5.5.50-1.el7_2.x86_64
mariadb-server-5.5.50-1.el7_2.x86_64
2、强制卸载所有
# rpm -e --nodeps mariadb-libs-5.5.50-1.el7_2.x86_64
# rpm -e --nodeps mariadb-5.5.50-1.el7_2.x86_64
# rpm -e --nodeps mariadb-server-5.5.50-1.el7_2.x86_64
参考:https://blog.csdn.net/ixiaoyou/article/details/81215240