環(huán)境介紹
操作系統(tǒng):Centos7.6
My SQL版本:8.0.30
本文使用的是當(dāng)前最新8.0.30版本垫挨,如果需要安裝的版本比8.0.30高或者低僧界,只要是8.0.*版本敞临,那就可以按照本文說明安裝简珠,基本不會(huì)有任何問題猜揪。
一惭墓、安裝準(zhǔn)備
1.卸載MariaDB
安裝My SQL的話會(huì)和MariaDB的文件沖突,所以需要先卸載掉MariaDB而姐。
1.1查看是否安裝mariadb
1.2 卸載
1.3 檢查是否卸載干凈
2.檢查依賴libaio(異步讀寫)
如果沒有安裝則執(zhí)行(安裝libaio)
yum -y install libaio?
如果沒有安裝則執(zhí)行(安裝numactl)
yum? -y install numactl
二腊凶、安裝MySQL
1.下載資源包
cd /usr/local
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.30-el7-x86_64.tar
2.解壓
注:本文安裝包上傳到了 /usr/local/ 目錄下
進(jìn)入安裝包目錄
cd /usr/local
拆分tar包和
tar -xvf mysql-8.0.30-el7-x86_64.tar
解壓安裝包
tar -zxvf mysql-8.0.30-el7-x86_64.tar.gz
3.重命名
3.1將解壓后的文件夾重命名為mysql
mv mysql-8.0.30-el7-x86_64/ mysql
4.創(chuàng)建存儲(chǔ)數(shù)據(jù)文件
mkdir mysql/data
5.設(shè)置用戶組并賦權(quán)
groupadd mysql
5.2創(chuàng)建用戶
-r:創(chuàng)建系統(tǒng)用戶
-g:指定用戶組
useradd -r -g mysql mysql
5.3更改屬主和數(shù)組
chown -R mysql:mysql /usr/local/mysql/
5.4更改權(quán)限
chmod -R 755 /usr/local/mysql/
6.初始化MySQL進(jìn)入MySQL的bin目錄
cd /usr/local/mysql/bin/
初始化
../mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
7.配置參數(shù)文件
nano /etc/my.cnf
[client]
port = 3306
socket = /usr/local/mysql/data/mysql.sock
default-character-set = utf8mb4
[mysql]?
default-character-set = utf8mb4
[mysqld]?
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
init_connect = 'SET NAMES utf8mb4'
port = 3306
socket = /usr/local/mysql/data/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
datadir = /usr/local/mysql/data
#lower_case_table_names=1
#如果要設(shè)置lower_case_table_names可以在初始化里面設(shè)置 ./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql --lower_case_table_names=1
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
設(shè)置my.cnf權(quán)限
配置后修改 /etc/my.cnf 的權(quán)限為644
8.啟動(dòng)MySQL
/usr/local/mysql/support-files/mysql.server start
9.設(shè)置軟連接,并重啟MySQL
ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
ln -s /usr/local/mysql/mysql.sock /var/mysql.sock
service mysql restart
10.登錄并更改密碼
mysql -uroot -p
Enter password: 輸入初始化隨機(jī)密碼
兩種改密方式二選一
alter user 'root'@'localhost' identified by '123456';
set password for root@localhost = '123456';
11.開放遠(yuǎn)程連接
mysql>use mysql;
msyql>update user set user.Host='%' where user.User='root';
mysql>flush privileges;? ? //刷新權(quán)限