centos7编译安装mysql5.7

5/24/2020 mysql

# 1.下载

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.40.tar.gz
1

# 2.解压

tar -xzvf mysql-boost-5.7.40.tar.gz
1

# 3.安装工具

yum install -y gcc gcc-c++ ncurses ncurses-devel cmake bison
1

# 4.安装mysql

cd mysql-5.7.40

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DMYSQL_DATADIR=/data/mysql_data \
-DSYSCONFDIR=/etc \
-DMYSQL_TCP_PORT=3306 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EXTRA_CHARSETS=1 \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DEXTRA_CHARSETS=all \
-DWITH_DEBUG=0 \
-DWITH_BOOST=/data/mysql-5.7.40/boost

#建议用多核编译
make -j8
make install

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
ln -s /usr/local/mysql/bin/* /usr/local/bin/
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

# 5.增加mysql用户

useradd mysql
#不让mysql用户登录
groupadd -r mysql && useradd -r -g mysql -s /sbin/nologin -M mysql
1
2
3

# 6.新建数据文件夹

cd /data
mkdir mysql_data
chown -R mysql:mysql mysql_data
chown -R /usr/local/mysql
1
2
3
4

# 7.初始化数据库

/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data

[root@191d5dc7ffab data]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data
2022-11-26T12:08:39.156007Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-11-26T12:08:39.332485Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-11-26T12:08:39.357464Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-11-26T12:08:39.417201Z 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: 0ff46517-6d83-11ed-b0e6-0242ac110002.
2022-11-26T12:08:39.422742Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-11-26T12:08:39.578265Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-11-26T12:08:39.578277Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-11-26T12:08:39.578644Z 0 [Warning] CA certificate ca.pem is self signed.
2022-11-26T12:08:39.680740Z 1 [Note] A temporary password is generated for root@localhost: qlrx_!vo_9hW

#初始密码
qlrx_!vo_9hW
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# 8.启动

/etc/init.d/mysqld start
1

# 9.登录

mysql -uroot -p
1

# 10.重置密码

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('pAssWord@123');
1

# 11.重新登录

show databases;

可以看到数据库,可以愉快使用
1
2
3
Last Updated: 11/27/2022, 6:58:30 PM