centos7.7 安装 mysql5.7.29

 

1. 下载安装包

 2. 卸载主机自带的mysql或mariadb

[root@liando02 ~]# rpm -qa | grep mysql
[root@liando02 ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.64-1.el7.x86_64
[root@liando02 ~]# rpm -e mariadb-libs-5.5.64-1.el7.x86_64 --nodeps

3.安装mysql5.7.29

上传安装包至/root/softbak/,解压到/usr/local/

[root@liando02 ~]# cd softbak/
[root@liando02 softbak]# ls
mysql-5.7.29-el7-x86_64.tar.gz
[root@liando02 softbak]# tar -xzvf mysql-5.7.29-el7-x86_64.tar.gz -C /usr/local/
...
[root@liando02 softbak]# cd /usr/local/
[root@liando02 local]# ls
bin etc games include lib lib64 libexec mysql-5.7.29-el7-x86_64 sbin share src
[root@liando02 local]# mv mysql-5.7.29-el7-x86_64/ mysql

创建mysql用户和组

[root@liando02 local]# groupadd mysql
[root@liando02 local]# useradd -r -g mysql -s /bin/false mysql

创建目录并授权

[root@liando02 local]# mkdir /var/lib/mysql
[root@liando02 local]# mkdir /usr/local/mysql/log
[root@liando02 local]# mkdir /usr/local/mysql/data
[root@liando02 local]# 
[root@liando02 local]# chown -R mysql:mysql /usr/local/mysql
[root@liando02 local]# chown -R mysql:mysql /var/lib/mysql

添加环境变量

[root@liando02 local]# vim ~/.bash_profile

PATH=$PATH:$HOME/bin:/usr/local/mysql/bin

[root@liando02 local]# source ~/.bash_profile

配置参数文件

[root@liando02 local]# vim /etc/my.cnf

[mysql]
default-character-set=utf8mb4
socket=/var/lib/mysql/mysql.sock

[mysqld]
port = 3306
socket=/var/lib/mysql/mysql.sock
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data/
character-set-server=utf8mb4
default-storage-engine=INNODB
innodb_buffer_pool_size = 200M
max_allowed_packet=16M
explicit_defaults_for_timestamp=1
log-output=FILE
general_log = 0
general_log_file=/usr/local/mysql/log/liandodb_general.err
slow_query_log = ON
slow_query_log_file=/usr/local/mysql/log/liandodb_query.err
long_query_time=10
log-error=/usr/local/mysql/log/liandodb_error.err

数据库初始化

[root@liando02 local]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
2020-05-21T02:15:36.432520Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-05-21T02:15:39.205018Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-05-21T02:15:39.855039Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-05-21T02:15:40.020428Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: f75b0826-9b08-11ea-a717-000c29fc8c72.
2020-05-21T02:15:40.033241Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-05-21T02:15:41.243316Z 0 [Warning] CA certificate ca.pem is self signed.
2020-05-21T02:15:41.717152Z 1 [Note] A temporary password is generated for root@localhost: YnnbNg-Vo4d7

配置mysql服务

[root@liando02 local]# vim /usr/lib/systemd/system/mysqld.service

[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 65536
LimitNPROC = 65536


root@liando02 local]# systemctl daemon-reload

查看服务状态

[root@liando02 local]# systemctl status mysqld
?.mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html

启动与关闭mysql

[root@liando02 local]# systemctl stop mysqld
[root@liando02 local]# systemctl start mysqld
[root@liando02 local]# 
[root@liando02 local]# systemctl status mysqld
?.mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2020-05-21 11:26:41 CST; 2s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 14523 (mysqld)
    Tasks: 27
   CGroup: /system.slice/mysqld.service
           ?..14523 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf

May 21 11:26:41 liando02 systemd[1]: Started MySQL Server.

设置开机自动启动

[root@liando02 local]# systemctl enable mysqld
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.

手动启动与关闭

启动:
nohup /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &
停止:
mysqladmin -uroot -p shutdown -S /var/lib/mysql/mysql.sock

设置root用户口令

[root@liando02 local]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.29-log

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

设置root远程登陆

mysql> grant all privileges on *.* to 'root'@'%' IDENTIFIED BY 'root' with grant option ;
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

测试远程登陆

[root@liando02 local]# mysql -h 10.0.20.93 -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.29-log MySQL Community Server (GPL)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

 

posted @ 2020-05-21 11:46  文水凡  阅读(472)  评论(0)    收藏  举报