MySQL部署
系统环境:CentOs7
1、创建存放MySQL文件的目录
[root@localhost ~]# cd /usr/local/
[root@localhost local]# mkdir Chengwangan
[root@localhost local]# cd Chengwangan/
[root@localhost Chengwangan]# mkdir Mysql
[root@localhost Chengwangan]# cd Mysql/
2、下载mysql官网获取RPM包
[root@localhost Mysql]# wget https://dev.mysql.com/downloads/repo/yum/
3、下载 mysql源安装包
[root@localhost Mysql]# wget
https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
4、安装mysql源
[root@localhost Mysql]# yum -y localinstall mysql57-community-release-el7-11.noarch.rpm
5、在线安装MySQL
[root@localhost Mysql]# yum -y install mysql-community-server
6、启动MySQL服务
[root@localhost Mysql]# systemctl start mysqld
7、设置开机启动
[root@localhost Mysql]# systemctl enable mysqld
[root@localhost Mysql]# systemctl daemon-reload
8、修改root本地登录密码
mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个临时的默认密码
[root@localhost Mysql]# vim /var/log/mysqld.log
找到:
2018-04-19T02:19:10.110319Z 1 [Note] A temporary password is generated for root@localhost: T:&hu/gyc2yD #这一行
这里的临时密码 T:&hu/gyc2yD
9、进入MySQL 输入刚才的MySQL临时密码
[root@localhost Mysql]# mysql -uroot -p"T:&hu/gyc2yD"
10、修改密码为 chengwangan (备注 mysql5.7默认密码策略要求密码必须是大小写字母数字特殊字母的组合,至少8位)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'chengwangan';
如果只是修改为一个简单的密码,会报以下错误:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
10.1、这个其实与validate_password_policy的值有关。
首先,修改validate_password_policy参数的值
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
这样,判断密码的标准就基于密码的长度了。这个由validate_password_length参数来决定。
10.2、修改validate_password_length的值=1
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
10.3、现在我们再次尝试修改简单密码测试是否还报错
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'chengwangan';
Query OK, 0 rows affected (0.00 sec)
11、设置允许远程登录
Mysql默认不允许远程登录,我们需要设置下,并且防火墙开放3306端口;
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'chengwangan' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> exit
Bye
先退出 开放3306端口
[root@localhost Mysql]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
FirewallD is not running
这里提示我防火墙没有在运行,因为我现在服务器的防火墙被我手动关闭,我们需要手动开启
[root@localhost Mysql]# systemctl start firewalld.service
[root@localhost Mysql]# systemctl enable firewalld.service
Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to /usr/lib/systemd/system/firewalld.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service.
现在再重新开放
[root@localhost Mysql]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success #返回结果为success就代表正常
[root@localhost Mysql]# firewall-cmd --reload
success
12、配置默认编码为utf8
修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
![](https://i-blog.csdnimg.cn/blog_migrate/7c4502df820abcb7aadd1e8e154fd238.png)
13、编辑保存完 重启MySQL服务
[root@localhost Mysql]# systemctl restart mysqld
14、进入数据库 查看下编码
[root@localhost Mysql]# mysql -uroot -p"chengwangan"
mysql> show variables like '%character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.01 sec)
15、测试
我们用本机的Navicat远程连接下刚部署的mysql
![](https://i-blog.csdnimg.cn/blog_migrate/52648539697e2429299dde379342e8ab.png)
本文来自 http://note.youdao.com/noteshare?id=8261aa6acf03d1227d316f9106be89e9