Linux 系統安裝 MySQL8.0.18

一、安裝方式

採取從第三方鏡像下載MySQL8.0.18的壓縮包的方式手動安裝。
鏡像地址:https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-8.0/

二、安裝步驟

1.將下載好的 mysql-8.0.18-el7-x86_64.tar.gz 通過 FinalShell 上傳到服務器的目錄,我放在 /home/zhjt

2.解壓縮並改名爲mysql

[zhjt@localhost ~]$ tar -zxvf mysql-8.0.18-el7-x86_64.tar.gz
[zhjt@localhost ~]$ mv mysql-8.0.18-el7-x86_64 mysql

3.創建mysql用戶組及用戶,並給mysql用戶設置密碼

[zhjt@localhost ~]# groupadd mysql
[zhjt@localhost ~]# useradd -r -g mysql mysql
[zhjt@localhost ~]# passwd mysql
更改用戶 mysql 的密碼 。
新的 密碼:123qweGHJ
重新輸入新的 密碼:123qweGHJ
passwd:所有的身份驗證令牌已經成功更新。

4.添加mysql配置文件:(/etc/my.cnf

[zhjt@localhost ~]# vim /etc/my.cnf

內容如下:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
basedir = /home/zhjt/mysql
datadir = /home/zhjt/mysql/data
port = 3306
# server_id = .....
socket = /tmp/mysql.sock
character-set-server = utf8
skip-name-resolve
log-error = /home/zhjt/mysql/data/error.log
pid-file = /home/zhjt/mysql/data/mysql.pid

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

然後保存退出。

5.在mysql目錄下新建data文件夾用於存放數據庫文件

[zhjt@localhost mysql]# mkdir data

6.在mysql當前目錄下設定目錄的訪問權限(注意後面的小點,表示當前目錄)

[zhjt@localhost mysql]# chown -R mysql .
[zhjt@localhost mysql]# chgrp -R mysql .

7.初始化數據庫

[zhjt@localhost mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/home/zhjt/mysql --datadir=/home/zhjt/mysql/data

打開日誌文件,找到初始密碼:

[zhjt@localhost mysql]# /home/zhjt/mysql/data/error.log

數據庫初始密碼

8. 啓動mysql

[zhjt@localhost mysql]# ./support-files/mysql.server start
Starting MySQL............ SUCCESS! 

9.登錄mysql,修改root用戶密碼

[zhjt@localhost mysql]# ./bin/mysql -uroot -p
Enter password: 4t?iQnB,+5co
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.17

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

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> use mysql
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.03 sec)

10.配置mysql允許遠程訪問

創建遠程登錄對象: CREATE USER 'root'@'%' IDENTIFIED BY '123456';
授權遠程登錄: grant all privileges on *.* to 'root'@'%' with grant option;
強制刷新: flush privileges;

mysql> CREATE USER 'root'@'%' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.01 sec)

mysql> grant all privileges on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

11.mysql啓動、停止、重啓命令

[zhjt@localhost mysql]# ./support-files/mysql.server start
Starting MySQL.. SUCCESS! 
[zhjt@localhost mysql]# ./support-files/mysql.server restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL.. SUCCESS! 
[zhjt@localhost mysql]# ./support-files/mysql.server stop
Shutting down MySQL.. SUCCESS!

三、參考文檔

https://blog.csdn.net/u010476739/article/details/100083959

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章