CentOS7安装MYSLQ5.7

CentOS7.3安装mysql

第一步:下载和安装mysql源

1.先下载 mysql源安装包

1
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

2.安装mysql源

1
yum -y localinstall mysql57-community-release-el7-11.noarch.rpm 

第二步:在线安装Mysql

1
yum -y install mysql-community-server

下载的东西比较多,要稍微等会

第三步:启动Mysql服务

1
systemctl start mysqld

第四步:设置开机启动

1
2
3
systemctl enable mysqld

systemctl daemon-reload

第五步:修改root本地登录密码

mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个临时的默认密码。

[root@localhost ~]# vi /var/log/mysqld.log

mysql的密码

这里的临时密码 eMV.R#mWe3ha

[root@localhost ~]# mysql -u root -p

Enter password:

输入临时密码 进入mysql命令行;

1
2
3
4

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'ZhipengWang2012@';

Query OK, 0 rows affected (0.00 sec)

修改密码为 ZhipengWang2012@ (备注 mysql5.7默认密码策略要求密码必须是大小写字母数字特殊字母的组合,至少8位)

第七步:设置允许远程登录

Mysql默认不允许远程登录,我们需要设置下,并且防火墙开放3306端口;

1
2
3
4
5
6
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '@LiShuai123' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> exit;

Bye

退出下;

centos7开启防火墙

1
2
3
4
5
6
7
8
9
10
11
12
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent

success

[root@localhost ~]# firewall-cmd --reload

success

[root@localhost ~]#

开放3306端口

第八步:配置默认编码为utf8

修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:

[mysqld]

character_set_server=utf8

init_connect=’SET NAMES utf8’

[root@localhost ~]# vi /etc/my.cnf

修改编码

编辑保存完 重启mysql服务;

[root@localhost ~]# systemctl restart mysqld

[root@localhost ~]#

查看下编码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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.00 sec)

注:都安装成功了之后,那个tar.gz的压缩包就可以删掉了,节省磁盘空间

linux下的mysql默认是大小写敏感的,通过java操作数据库的时候会出现找不到表的情况,需要设置大小写不敏感

1
2
vim /etc/my.cnf
[mysqld]后添加添加lower_case_table_names=1

设置大小写不敏感

1
2
3
4
5
虚拟机中mysql的地址如下:
10.9.32.171
账号root
密码:root

CentOs6.8安装mysql

https://www.cnblogs.com/saneri/p/6617415.html