安装mysql5.7
安装mysql5.7
-
在安装MySQL服务的时候
[root@localhost ~]# yum -y install mysql-community-server
-
遇到以下报错
Downloading packages: warning: /var/cache/yum/x86_64/2.1903/mysql57-community/packages/mysql-community-common-5.7.37-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY Public key for mysql-community-common-5.7.37-1.el7.x86_64.rpm is not installed (1/4): mysql-community-common-5.7.37-1.el7.x86_64.rpm | 311 kB 00:00:01 (2/4): mysql-community-libs-5.7.37-1.el7.x86_64.rpm | 2.4 MB 00:00:01 (3/4): mysql-community-client-5.7.37-1.el7.x86_64.rpm | 25 MB 00:00:08 (4/4): mysql-community-server-5.7.37-1.el7.x86_64.rpm | 174 MB 00:00:42 ------------------------------------------------------------------------------------------------------------------------------ Total 4.4 MB/s | 202 MB 00:00:45 Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql Importing GPG key 0x5072E1F5: Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>" Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5 Package : mysql57-community-release-el7-10.noarch (@/mysql57-community-release-el7-10.noarch) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql Public key for mysql-community-server-5.7.37-1.el7.x86_64.rpm is not installed Failing package is: mysql-community-server-5.7.37-1.el7.x86_64 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
-
需要需要以下
yum
文件,指定某个版本vi /etc/yum.repos.d/mysql-community.repo # Enable to use MySQL 5.6 [mysql56-community] name=MySQL 5.6 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/ enabled=1 gpgcheck=1 # gpgcheck=0表示默认此版本 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
启动MySQL
-
启动MySQL服务
systemctl start mysqld.service
-
重启
systemctl restart mysqld.service
-
停止
systemctl stop mysqld.service
-
查看状态
systemctl status mysqld.service
-
配置MySQL的开机启动
systemctl enable mysqld
-
刷新配置生效
systemctl daemon-reload
登陆MySQL
-
第一次登陆,先查看内置密码
grep "password" /var/log/mysqld.log
-
用
root
登陆mysql -u root -p
- 需要进行修改密码
SET PASSWORD = PASSWORD('密码');
mysql> set global validate_password_policy=0; //改变密码等级 mysql> set global validate_password_length=4; //改变密码最小长度
-
配置远程登陆
MySQL默认root用户只能本地登录,如果要远程连接,要简单设置下,这里直接用root来远程登录不添加其他角色。
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '1234' WITH GRANT OPTION;
*.*
的意思是所有库的所有表To
后面跟的是用户名@
后面跟的是ip
地址%
代表所有ip
地址identified by
后面的是密码
flush privileges;
需要注意
mysql
的配置文件中的bindaddress
的参数和skip-networking
配置bindaddress
: 设定哪些ip地址被配置,使得mysql
服务器只回应哪些ip地址的请求),最好注释掉该参数或设置成为127.0.0.1以外的值skip-networking
: 如果设置了该参数项,将导致所有TCP/IP
端口没有被监听,也就是说出了本机,其他客户端都无法用网络连接到本mysql服务器,所以应该注释掉该参数
添加端口
-
添加
3306
端口firewall-cmd --zone=public --add-port=3306/tcp --permanent;
-
查看防火墙状态
systemctl status firewalld
-
打开防火墙
systemctl start firewalld
-
重新启用
3306
端口firewall-cmd --zone=public --add-port=3306/tcp --permanent;
-
重启防火墙
firewall-cmd --reload
收尾动作
-
查看
MySQL
的配置文件cat /etc/my.cnf
[root@blue-ocean tmp]# cat /etc/my.cnf # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html [mysqld] # # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
-
在
vim /etc/my.cnf
中[mysqld] character_set_server=utf8 init_connect='SET NAMES utf8'
-
默认配置文件路径
/etc/my.cnf #这是mysql的主配置文件 /var/lib/mysql #mysql数据库的数据库文件存放位置 /var/log mysql #数据库的日志输出存放位置