groupadd mysql
useradd -g mysql -s /sbin/nologin mysqln
yum install -y ncurses-devel libaio-devel gcc gcc-c++ numactl libaio glibc cmake autoconf
[root@localhost mysql]# ls
mysql-5.7.40-linux-glibc2.12-x86_64.tar.gz
[root@localhost mysql]# tar -zxvf mysql-5.7.40-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
mysql-5.7.40-linux-glibc2.12-x86_64/bin/myisam_ftdump
mysql-5.7.40-linux-glibc2.12-x86_64/bin/myisamchk
mysql-5.7.40-linux-glibc2.12-x86_64/bin/myisamlog
mysql-5.7.40-linux-glibc2.12-x86_64/bin/myisampack
mysql-5.7.40-linux-glibc2.12-x86_64/bin/mysql
mysql-5.7.40-linux-glibc2.12-x86_64/bin/mysql_client_test_embedded
mysql-5.7.40-linux-glibc2.12-x86_64/bin/mysql_config_editor
mysql-5.7.40-linux-glibc2.12-x86_64/bin/mysql_embedded
解压完成之后进入/usr/local
[root@localhost local]# ls
bin etc games include lib lib64 libexec mysql-5.7.40-linux-glibc2.12-x86_64 sbin share src
[root@localhost local]# pwd
/usr/local
[root@localhost local]# ls
bin etc games include lib lib64 libexec mysql-5.7.40-linux-glibc2.12-x86_64 sbin share src
[root@localhost local]# mv mysql-5.7.40-linux-glibc2.12-x86_64/ mysql5.7.40
[root@localhost local]# ls
bin etc games include lib lib64 libexec mysql5.7.40 sbin share src
[root@localhost local]#
echo "export PATH=$PATH:/usr/local/mysql5.7.40/bin" >> /etc/profile
source /etc/profile
[root@localhost local]# ls
bin etc games include lib lib64 libexec mysql5.7.40 sbin share src
[root@localhost local]# chown -R mysql.mysql mysql5.7.40/
[root@localhost local]# ll
总用量 0
drwxr-xr-x. 2 root root 6 4月 11 2018 bin
drwxr-xr-x. 2 root root 6 4月 11 2018 etc
drwxr-xr-x. 2 root root 6 4月 11 2018 games
drwxr-xr-x. 2 root root 6 4月 11 2018 include
drwxr-xr-x. 2 root root 6 4月 11 2018 lib
drwxr-xr-x. 2 root root 6 4月 11 2018 lib64
drwxr-xr-x. 2 root root 6 4月 11 2018 libexec
drwxr-xr-x 9 mysql mysql 129 3月 17 18:33 mysql5.7.40
drwxr-xr-x. 2 root root 6 4月 11 2018 sbin
drwxr-xr-x. 5 root root 49 2月 16 18:20 share
drwxr-xr-x. 2 root root 6 4月 11 2018 src
[root@localhost local]#
在根目录创建 /mysql
mkdir /msyql
然后进入 /mysql
mkdir mysql_data
chown -R mysql:mysql mysql_data/
touch mysqld.log
chown -R mysql:mysql mysqld.log
结果如下
[root@localhost mysql]# ll
总用量 1258124
-rw-r--r-- 1 root root 678001736 3月 17 18:26 mysql-5.7.40-linux-glibc2.12-x86_64.tar.gz
drwxr-xr-x 2 mysql mysql 6 3月 17 18:51 mysql_data
-rw-r--r-- 1 mysql mysql 0 3月 17 18:52 mysqld.log
cd /usr/local/mysql5.7.40
# 初始化命令 datadir为上面步骤创建存放数据的位置
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql5.7.40/ --datadir=/mysql/mysql_data/
初始化完成
[root@localhost mysql5.7.40]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql5.7.40/ --datadir=/mysql/mysql_data/
2023-03-22T09:40:27.256362Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2023-03-22T09:40:27.665979Z 0 [Warning] InnoDB: New log files created, LSN=45790
2023-03-22T09:40:27.801258Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2023-03-22T09:40:27.887321Z 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: 941b9bac-c895-11ed-9069-000c29f766f6.
2023-03-22T09:40:27.890207Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2023-03-22T09:40:28.178688Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2023-03-22T09:40:28.178708Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2023-03-22T09:40:28.179324Z 0 [Warning] CA certificate ca.pem is self signed.
2023-03-22T09:40:28.274175Z 1 [Note] A temporary password is generated for root@localhost: 1g%ddU71Vkum
结尾的:1g%ddU71Vkum 是初始化密码
cd /usr/local/mysql5.7.40/
mkdir run
cd run/
touch mysqld.pid mysql.sock
cd ..
mkdir log
touch mysql_error.log
修改 /etc/my.cnf
先移动下系统的做备份,之后再创建新的配置文件去编写
mv my.cnf A_mysql.cof
vim /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql5.7.40
datadir=/mysql/mysql_data
port=3306
socket=/usr/local/mysql5.7.40/mysql.sock
character-set-server=utf8mb4
log-error=/var/log/mysqld.log
pid-file=/tmp/mysqld.pid
[mysql]
socket=/usr/local/mysql5.7.40/mysql.sock
[client]
socket=/usr/local/mysql5.7.40/mysql.sock
# 先移动
cp /usr/local/mysql5.7.40/support-files/mysql.server /etc/init.d/mysqld
# 添加执行权限
chmod +x /etc/init.d/mysqld
# 修改文件信息 主要修改 basedir(mysql路径) 与 datadir(数据路径)
vim /etc/init.d/mysqld
basedir=/usr/local/mysql5.7.40
datadir=/mysql/mysql_data
/etc/init.d/mysqld start
[root@localhost init.d]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/mysql/mysql_data/localhost.localdomain.err'.
SUCCESS!
mysql -u root -p
# 之后输入初始密码 1g%ddU71Vkum
[root@localhost mysql5.7.40]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.40
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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>
新密码为123456
set password for root@localhost = password('123456');
vim /usr/lib/systemd/system/mysql.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=https://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/mysql5.7.40/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
# 重载
systemctl daemon-reload
# 开启mysql服务
systemctl start mysql
查看状态
# systemctl status mysql