centos下mysql配置
centos7下安装mysql(完整配置)
1. 下载并安装MySQL官方的Yum Repository
[root@localhost ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
- 1
使用上面的命令直接安装Yum Repository
[root@localhost ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm
- 1
安装MySQL服务器
root@localhost ~]# yum -y install mysql-community-server
- 1
2. MySQL数据库设置
启动MySQL
[root@localhost ~]# systemctl start mysqld.service
- 1
查看MySQL运行状态
[root@localhost ~]# systemctl status mysqld.service
- 1
此时MySQL已经开始正常运行,需要找出root的密码
[root@localhost ~]# grep "password" /var/log/mysqld.log
- 1
如下命令登录mysql
# mysql -uroot -p
- 1
输入初始密码,此时不能做任何事情,因为MYSQL默认必须修改密码才能正常使用
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
这里会遇到一个问题,新密码设置过于简单会报错
- 1
- 2
- 3
可通过如下命令查看完整的初始密码规则
mysql>show variables like 'validate_password';
- 1
可通过如下命令修改
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;
- 1
- 2
还有一个问题就是Yum Repository,以后每次 yum 操作都会自动更新,需要把这个卸载掉
[root@localhost ~]# yum -y remove mysql57-community-release-el7-10.noarch
- 1
远程登录数据库出现下面出错信息
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;
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
修改mysql数据库总的user表使相的用户能从某一主机登录
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
- 1
- 2
- 3
客户端提供MYSQL的环境,但是不支持中文,通过以下命令可以查看mysql的字符集
mysql>show variables like 'character_set%';
- 1
显示如下:
为了让 MySQL支持中文,需要把字符集改成UTF-8,方法如下
# vim /etc/my.cnf
- 1
改成如下内容
[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
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
重启mysql服务
# service mysqld restart
- 1
重新查看数据库编码
show variables like 'character_set%';
- 1
效果如下,可看到都改为utf-8
</div>
<link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-b6c3c6d139.css" rel="stylesheet">
<div class="more-toolbox">
<div class="left-toolbox">
<ul class="toolbox-list">
<li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true">
<use xlink:href="#csdnc-thumbsup"></use>
</svg><span class="name">点赞</span>
<span class="count">22</span>
</a></li>
<li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{"mod":"popu_824"}"><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-csdnc-Collection-G"></use>
</svg><span class="name">收藏</span></a></li>
<li class="tool-item tool-active is-share"><a href="javascript:;" data-report-click="{"mod":"1582594662_002"}"><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-csdnc-fenxiang"></use>
</svg>分享</a></li>
<!--打赏开始-->
<!--打赏结束-->
<li class="tool-item tool-more">
<a>
<svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg>
</a>
<ul class="more-box">
<li class="item"><a class="article-report">文章举报</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="person-messagebox">
<div class="left-message"><a href="https://blog.csdn.net/baidu_32872293">
<img src="https://profile.csdnimg.cn/8/C/B/3_baidu_32872293" class="avatar_pic" username="baidu_32872293">
<img src="https://g.csdnimg.cn/static/user-reg-year/1x/4.png" class="user-years">
</a></div>
<div class="middle-message">
<div class="title"><span class="tit"><a href="https://blog.csdn.net/baidu_32872293" data-report-click="{"mod":"popu_379"}" target="_blank">zengrui_0337</a></span>
</div>
<div class="text"><span>发布了27 篇原创文章</span> · <span>获赞 29</span> · <span>访问量 5万+</span></div>
</div>
<div class="right-message">
<a href="https://im.csdn.net/im/main.html?userName=baidu_32872293" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-letter">私信
</a>
<a class="btn btn-sm bt-button personal-watch" data-report-click="{"mod":"popu_379"}">关注</a>
</div>
</div>
</div>
</article>