下载MySQL官方的Yum Repository
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
通过yum命名安装MYSQL
yum -y install mysql57-community-release-el7-10.noarch.rpm
安装MySQL服务器
yum -y install mysql-community-server
启动MySQL
systemctl start mysqld.service
查看MySQL运行状态
systemctl status mysqld.service
如果Active为active(running)则表示mysql正常启动成功
此时需要找出root的密码
grep "password" /var/log/mysqld.log
2020-09-11T04:00:08.625129Z 1 [Note] A temporary password is generated for root@localhost: sE(1d+#J<j4L
说明密码为:sE(1d+#J<j4L
接下来修改MYSQL登录密码。
先登录MYSQL
# mysql -uroot -p
输入初始密码,此时不能做任何事情,因为MYSQL默认必须修改密码才能正常使用
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
这里可能会报错,提示新密码设置过于简单。报错信息如下:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
可通过如下命令进行修改密码格式,然后在重新设置密码。
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;
还有一个问题就是Yum Repository,以后每次 yum 操作都会自动更新,需要把这个卸载掉
yum -y remove mysql57-community-release-el7-10.noarch
远程登录数据库出现下面出错信息
ERROR 2003 (HY000): Can’t connect to MySQL server on ‘xxx.xxx.xxx.xxx’,
原因是没有授予相应的权限
#任何主机
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
#指定主机
mysql>GRANT ALL PRIVILEGES ON *.* TO 'jack'@’10.10.50.127’ IDENTIFIED BY '654321' WITH GRANT OPTION;
然后刷新权限
mysql>flush privileges;
修改mysql数据库总的user表使相的用户能从某一主机登录
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
客户端提供MYSQL的环境,但是不支持中文,通过以下命令可以查看mysql的字符集
mysql>show variables like 'character_set%';
显示如下:
为了让 MySQL支持中文,需要把字符集改成UTF-8,方法如下
# vim /etc/my.cnf
改成如下内容
[client]
port=3306
socket=/var/lib/mysql/mysql.sock
default-character-set=utf8
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
character-set-server=utf8
[mysql]
no-auto-rehash
default-character-set=utf8
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
重启mysql服务
# service mysqld restart
重新查看数据库编码
show variables like 'character_set%';
效果如下,可看到都改为utf-8
内容来源于网络,如有侵权,请联系作者删除!