1、先卸載當前系統中已安裝的mariadb 2、安裝mysql依賴包 3、下載mysql 4、解壓mysql壓縮包,創建mysql目錄 5、創建mysql虛擬用戶和組 6、配置/etc/my.cnf 7、配置環境變數 8、初始化資料庫 初始化完成後,會自動為root帳戶生成一個初始密碼,要記錄下來 ...
1、先卸載當前系統中已安裝的mariadb
rpm -qa | grep mariadb
rpm -e --nodeps 文件名
2、安裝mysql依賴包
yum install gcc gcc-c++ openssl openssl-devel libaio libaio-devel ncurses ncurses-devel
3、下載mysql
wget https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-8.0/mysql-8.0.15-el7-x86_64.tar.gz
4、解壓mysql壓縮包,創建mysql目錄
tar xf mysql-8.0.15-el7-x86_64.tar.gz -C /application/
mv mysql-8.0.15-el7-x86_64/ mysql
cd mysql
mkdir data ----創建資料庫文件目錄
mkdir logs ----創建日誌目錄
/application/mysql/logs/error.log 創建日誌
5、創建mysql虛擬用戶和組
useradd -s /sbin/nologin -M mysql
#groupadd mysql #添加用戶組
#useradd -r -g mysql mysql #創建mysql用戶,並添加到mysql用戶組
chown -R mysql.mysql /application/mysql
6、配置/etc/my.cnf
[mysqld]
basedir=/application/mysql
datadir=/application/mysql/data
port=3306
socket=/tmp/mysql.sock
pid-file=/application/mysql/python.pid
log-error=/application/mysql/logs/error.log
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
character_set_server = utf8
[client]
default-character-set = utf8
7、配置環境變數
echo "export PATH=$PATH:/application/mysql/bin" >> /etc/profile
source /etc/profile
8、初始化資料庫
./bin/mysqld --initialize --user=mysql --basedir=/application/mysql/ --datadir=/application/mysql/data
初始化完成後,會自動為root帳戶生成一個初始密碼,要記錄下來
9、製作啟動文件
cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
10.啟動mysql服務
/etc/init.d/mysqld start
停止mysql服務
/etc/init.d/mysqld stop
11.改密碼
alter user root@'localhost' identified by '123456';
12.創建遠程連接帳號
create user root@'%' identified by '21345';
grant all on *.* to root@'%' with grant option;
flush privileges;