Detailed steps and notes for compiling and installing MySQL database

1. Install the Mysql environment dependency package

[root@localhost~]#
yum -y install \
ncurses \
ncurses-devel \
bison \
cmake

2. Create a running user

[root@localhost ~] useradd -s /sbin/nologin mysql

3. Compile and install

First upload the installation package to the opt directory

[root@localhost ~]cd /opt
[root@localhost opt]# tar xzvf mysql-boost-5.7.20.tar.gz
[root@localhost opt]# cd /opt/mysql-5.7.20/
[root@localhost mysql-5.7.20]#
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYsQL_UIx_ADDR=/usr/local/mysql/mysql.sock \
-DsYsCONFDIR=/etc \
-DsySTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DwITH_INNOBASE_STORAGE_ENGINE=1\
-DWITH_ARCHIVE_STORAGE_ENGINE=1\
-DWITH_BLACKHOLE_STORAGE_ENGINE=1\
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1\
-DMYsQL_DATADIR=/usr/local/mysql/data \
-DWITH_BoOsT=boost \
-DWITH_sYSTEMD=1


[root@localhost mysql-5.7.20]# make && make install

**Note:** When compiling, you can use make -j4 to bring you the feeling of taking off (4 is the maximum number of cores)

4. Adjust the permissions of the database directory

[root@localhost mysql-5.7.20]#chown -R mysql:mysql /usr/local/mysql/

5. Adjust the configuration file

[root@localhost mysql-5.7.20]#vi /etc/my.cnf
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysqlj
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
[root@localhost mysql-5.7.20]# chown mysql:mysql /etc/my.cnf

6. Set environment variables

[root@localhost mysql-5.7.20]# echo 'PATH=/usr/local/mysql/bin:/usr/local/mysq/lib:$PATH' >>/etc/profile
[root@localhost mysql-5.7.20]# echo 'export PATH > >/etc/profile
[root@localhost mysql-5.7.20]# source /etc/profile

7. Initialize the database

[root@localhost mysql-5.7.20]# cd /usr/local/mysql/

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

[root@localhost mysql-5.7.20]# cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/

8. The database is started, closed, and status

[root@localhost mysql-5.7.20]# systemctl enable mysqld		#开机自启
[root@localhost mysql-5.7.20]# systemctl start mysqld			#开启
[root@localhost mysql-5.7.20]# systemctl stop mysqld			#停止
[root@localhost mysql-5.7.20]# systemctl status mysqld		#查看状态
[root@localhost mysql-5.7.20]# netstat -anpt | grep 3306		#过滤3306端口

9. Set Mysql password

[root@localhost mysql-5.7.20]# mysqladmin -u root -p password

**Note: **At first, if there is no password, press Enter directly, then enter the password 123123, and confirm 123123 again. This is run under the root account

10. Log in to the database

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

**Note: **After typing this command, enter the password "123123" you previously set to log in to the database.
If you install it on the database, remember to finish the installation! ! Remember! ! Snapshot, for the convenience of initialization in the future.

Guess you like

Origin blog.csdn.net/weixin_48190875/article/details/108642168
Recommended