Linux系統安裝MySQL5.7.28

環境
CentOS Linux release 7.6.1810 (Core)
mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz

下載頁面
https://downloads.mysql.com/archives/community/
下載地址
https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz

1、下載並解壓

cd /usr/local/soft/package
# 下載mysql
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
# 解壓
tar -xzvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.28-linux-glibc2.12-x86_64 /usr/local/soft
# 建立軟連接
ln -s /usr/local/soft/mysql-5.7.28-linux-glibc2.12-x86_64 /usr/local/soft/mysql

2、檢查是否安裝過mysql,如果有則刪除。

# 檢查是否安裝過mysql
rpm -qa | grep mysql
# 如果有則刪除
rpm -e --nodeps mysql-libs-5.5.60-1.x86_64

# 檢查是否安裝過mariadb
rpm -qa | grep mariadb
# 如果有則刪除
rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64

3、創建 mysql 用戶組 和 mysql 用戶

# 檢查是否已經存在
cat /etc/group | grep mysql
cat /etc/passwd |grep mysql
# 如果沒有則創建
groupadd mysql
useradd -r -g mysql mysql

4、修改權限

cd /usr/local/soft
chown -R mysql:mysql mysql/
chmod -R 755 mysql/

5、初始化mysql,記住命令行末尾的密碼

# 創建data文件夾
mkdir /usr/local/soft/mysql/data
# 編譯安裝並初始化mysql,記住命令行末尾的密碼
/usr/local/soft/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/soft/mysql/data --basedir=/usr/local/soft/mysql

執行結果如下,記住命令行末尾的密碼S*ppd.%!f6sp

[root@bogon soft]# mkdir /usr/local/soft/mysql/data
[root@bogon soft]# /usr/local/soft/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/soft/mysql/data --basedir=/usr/local/soft/mysql
2020-04-02T06:12:50.293648Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-04-02T06:12:51.410510Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-04-02T06:12:51.589844Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-04-02T06:12:51.675551Z 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: fbd78562-74a8-11ea-9174-000c290e1656.
2020-04-02T06:12:51.687605Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-04-02T06:12:55.710051Z 0 [Warning] CA certificate ca.pem is self signed.
2020-04-02T06:12:56.581188Z 1 [Note] A temporary password is generated for root@localhost: S*ppd.%!f6sp

6、創建配置文件,如果不創建默認啓動/usr/local/mysql目錄下的mysql

vim /etc/my.cnf
[mysqld]

port=3306
basedir=/usr/local/soft/mysql
datadir=/usr/local/soft/mysql/data
socket=/tmp/mysql.sock
user=mysql
tmpdir=/tmp
# 忽略表名大小寫
lower_case_table_names=1
# sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

bind-address = 0.0.0.0
max_connections=200
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
default-storage-engine=INNODB
innodb_buffer_pool_size=64MB
max_allowed_packet=16M
skip-name-resolve

[mysqld_safe]

log-error=/usr/local/soft/mysql/data/error.log
pid-file=/usr/local/soft/mysql/data/mysql.pid

[mysql]

default-character-set=utf8mb4

[client]

socket=/tmp/mysql.sock
default-character-set=utf8mb4

7、啓動mysql服務,並設置爲開機啓動

# 創建軟連接,作爲服務
ln -s /usr/local/soft/mysql/support-files/mysql.server /etc/init.d/mysql

service mysql start
service mysql restart
service mysql stop

開機啓動

# 添加可執行權限
chmod +x /etc/init.d/mysql
# 添加 mysql 服務
chkconfig --add mysql
# 查看服務列表(若 3 4 5 爲 off,執行:chkconfig --level 345 mysql on)
chkconfig --list
# 重啓服務器
reboot

8、登錄mysql

# 創建軟連接 可在任意目錄登錄mysql
ln -s /usr/local/soft/mysql/bin/mysql /usr/bin
# 登錄mysql
mysql -u root -p

如下:

[root@bogon ~]# mysql -u root -p
Enter password: 

9、第一次登錄需要修改密碼和允許遠程登錄

mysql>alter user 'root'@'localhost' identified by '123456';
mysql>use mysql;
msyql>update user set user.Host='%' where user.User='root';
mysql>flush privileges;
mysql>quit
mysql>use mysql;
mysql> select host from user where user = 'root';
+------+
| host |
+------+
| %    |
+------+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章