Deploy MySQL 5.7

First, deploy and install MySQL

Note: Before installing MySQL, you need to uninstall the existing mariadb, and then you need to install the gcc environment
1. Install cmake

  [root@mysql ~]# wget https://github.com/Kitware/CMake/archive/v3.16.4.tar.gz                # 下载cmake
[root@mysql ~]# yum -y install openssl-devel          # 有时候安装cmake的时候会报错,一般就是openssl这个依赖包没有装
[root@mysql ~]# tar zxf cmake-3.16.4.tar.gz 
[root@mysql ~]# cd cmake-3.16.4/
[root@mysql cmake-3.16.4]# ./bootstrap 
[root@mysql cmake-3.16.4]# gmake && gmake install 

2. Install ncurses

[root@mysql ~]# wget ftp://ftp.gnu.org/gnu/ncurses/ncurses-5.9.tar.gz
[root@mysql cmake-3.16.4]# cd ..
[root@mysql ~]# tar zxf ncurses-5.9.tar.gz 
[root@mysql ~]# cd ncurses-5.9/
[root@mysql ncurses-5.9]# ./configure && make && make install 

3. Install bison

[root@mysql ~]# wget http://ftp.gnu.org/gnu/bison/bison-3.1.tar.gz
[root@mysql ~]# tar zxf bison-3.1.tar.gz 
[root@mysql ~]# cd bison-3.1/
[root@mysql bison-3.1]# ./configure && make && make install 

4. Install boost

[root@mysql ~]# wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz/download
[root@mysql ~]# tar zxf boost_1_59_0.tar.gz 
[root@mysql ~]# mv boost_1_59_0/ /usr/local/boost

5. Create MySQL users and required directories

[root@mysql ~]# useradd -r -M -s /sbin/nologin mysql 
[root@mysql ~]# mkdir -p /usr/local/mysql/data

6. Install and initialize MySQL

[root@mysql ~]# tar zxf mysql-5.7.29.tar.gz 
[root@mysql ~]# cd mysql-5.7.29/
[root@mysql mysql-5.7.29]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_SYSTEMD=1 -DWITH_BOOST=/usr/local/boost && make && make install
#配置环境变量
[root@mysql mysql-5.7.29]# echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
[root@mysql mysql-5.7.29]# source /etc/profile
#更改属主属组
[root@mysql mysql-5.7.29]# cd /usr/local/
[root@mysql local]# chown -R mysql:mysql mysql/
#进行初始化
[root@mysql ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

When the initialization operation is performed, the last line of the returned information will display the password of the root user of the MySQL database, or it may not be displayed. That means that the root user has no password. The passwords shown here are as follows (this password is recommended to be copied to a In the text, you will need to change the password after a while. If the password is lost, you need to re-initialize MySQL and re-initialize the directory: delete all files and directories in the / usr / local / mysql / data directory before you can re-initialize successfully ):
Deploy MySQL 5.7
7, configure and start MySQL

#再次修改当前目录下的属组及属主(初始化后,产生的一些文件)
[root@mysql ~]# chown -R mysql:mysql /usr/local/mysql/
#编写MySQL的主配置文件
[root@mysql ~]# vim /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
server_id=1             #当架构中存在多个MySQL服务器,那么这个server_id就是各个MySQL数据库的唯一性。
socket=/usr/local/mysql/mysql.sock
log-error=/usr/local/mysql/data/mysqld.err
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
#复制其服务脚本并启动MySQL
[root@mysql ~]# cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system
[root@mysql ~]# systemctl start mysqld 

When the start command is executed, an error will be reported. . . . . .
Deploy MySQL 5.7
You can use the MySQL error log to locate the problem:

[root@mysql mysql]# tail data/mysqld.err 
2020-04-10T16:41:01.982743Z 0 [Note] InnoDB: Buffer pool(s) load completed at 200411  0:41:01
2020-04-10T16:41:01.985619Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2020-04-10T16:41:01.985630Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
2020-04-10T16:41:01.986055Z 0 [Warning] CA certificate ca.pem is self signed.
2020-04-10T16:41:01.986086Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2020-04-10T16:41:01.986148Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2020-04-10T16:41:01.986174Z 0 [Note] IPv6 is available.
2020-04-10T16:41:01.986180Z 0 [Note]   - '::' resolves to '::';
2020-04-10T16:41:01.986195Z 0 [Note] Server socket created on IP: '::'.
2020-04-10T16:41:01.987181Z 0 [ERROR] Can't start server: can't check PID filepath: No such file or directory

Solution:
modify the PID path specified in its service control script:

[root@mysql mysql]# vim /usr/lib/systemd/system/mysqld.service 
PIDFile=/usr/local/mysql/mysqld.pid        # 修改这两行
ExecStart=/usr/local/mysql/bin/mysqld --daemonize --pid-file=/usr/local/mysql/mysqld.pid $MYSQLD_OPTS

Make sure that the MySQL database starts successfully

[root@mysql ~]# systemctl daemon-reload          # 重载配置文件
[root@mysql ~]# systemctl restart mysqld         # 重启服务
[root@mysql ~]# netstat -anput | grep 3306       # 确认服务启动
tcp6       0      0 :::3306                 :::*                    LISTEN      92944/mysqld  

8. Change MySQL root login password

[root@mysql ~]# mysqladmin -u root -p password '123.com'
Enter password:            #这里输入初始化MySQL后返回的密码
#执行成功后,会输出一些warning类的提示信息,无关紧要的,是提示直接将新密码暴露在了终端,不安全。
[root@mysql ~]# mysql -u root -p123.com       # 使用新密码登录

Guess you like

Origin blog.51cto.com/14227204/2486471