您好,登錄后才能下訂單哦!
系統環境:CentOS 7.6
關閉防火墻等安全機制
檢查系統有沒有默認安裝的數據庫
[root@mysqlmaster ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
卸載掉默認數據庫
[root@mysqlmaster ~]# rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps
下載預編譯二進制包
[root@mysqlmaster ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
解壓包
[root@mysqlmaster ~]# tar fx mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /usr/local
給mysql重命名 或者創建軟連接
[root@mysqlmaster ~]# mv /usr/local/mysql-5.7.18-linux-glibc2.5-x86_64/ /usr/local/mysql
創建軟連接 (如果重命名了就不用創建軟連接了)
[root@mysqlmaster ~]# ln -s /usr/local/mysql-5.7.18-linux-glibc2.5-x86_64/ /usr/local/mysql
創建用戶和組
[root@mysqlmaster ~]# groupadd mysql
[root@mysqlmaster ~]# useradd -r -g mysql mysql
給mysql寫個配置文件
[root@mysqlmaster ~]# vim /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
symbolic-links=0
[mysqld_safe]
log-error=/usr/local/mysql/logs/error.log
pid-file=/usr/local/mysql/mysql.pid
[client]
socket=/usr/local/mysql/mysql.sock
配置文件寫好后緊接著創建配置文件里提到的路徑
[root@mysqlmaster ~]# mkdir -p /usr/local/mysql/data
[root@mysqlmaster ~]# mkdir -p /usr/local/mysql/logs
[root@mysqlmaster ~]# touch /usr/local/mysql/logs/error.log
授權
[root@mysqlmaster ~]# chown -R mysql.mysql /usr/local/mysql/
[root@mysqlmaster ~]# chown -R mysql.mysql /etc/my.cnf
安裝
[root@mysqlmaster ~]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
額外做一下安全加固
[root@mysqlmaster ~]# /usr/local/mysql/bin/mysql_ssl_rsa_setup --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
copy啟動腳本
[root@mysqlmaster ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
修改文件
[root@mysqlmaster ~]# sed -i '46c basedir=/usr/local/mysql' /etc/init.d/mysqld
[root@mysqlmaster ~]# sed -i '47c datadir=/usr/local/mysql/data' /etc/init.d/mysqld
[root@mysqlmaster ~]# sed -i '63c mysql_pid_file_path=/usr/local/mysql/data/mysqld.pid' /etc/init.d/mysqld
啟動數據庫
[root@mysqlmaster ~]# /etc/init.d/mysqld start
啟動數據庫成功!
設置軟連接方便啟動
[root@mysqlmaster ~]# ln -s /usr/local/mysql/bin/* /usr/local/sbin/
修改密碼(五交互式高大上修改密碼),并登錄成功!
[root@mysqlmaster ~]# mysql -e "use mysql;alter user 'root'@'localhost' identified by '123456';"
[root@mysqlmaster ~]# mysql -uroot -p123456
加入到systemctl 進行管理
cat > /usr/lib/systemd/system/mysqld.service <<EOF
[mysqld]
[Unit]
Description=MySQL
SourcePath=/etc/init.d/mysqld
Before=shutdown.target
[Service]
User=mysql
Type=forking
ExecStart=/etc/init.d/mysqld start
ExecStop=/etc/init.d/mysqld stop
[Install]
WantedBy=multi-user.target
EOF
重新加載服務的配置文件,并重啟mysqld
systemctl daemon-reload
systemctl restart mysqld
查看日志是否啟動成功
[root@mysqlmaster ~]# journalctl -f
啟動成功!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。