您好,登錄后才能下訂單哦!
本文主要給大家介紹mysql-5.7.18自定義安裝路徑講義,其所涉及的東西,從理論知識來獲悉,有很多書籍、文獻可供大家參考,從現(xiàn)實意義角度出發(fā),億速云累計多年的實踐經(jīng)驗可分享給大家。
libaio
yum install -y libaio
useradd -s /bin/false -M mysql
cd /tools
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
tar -zxf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /application/
cd /application/
mv mysql-5.7.18-linux-glibc2.5-x86_64/ mysql-5.7.18
ln -s mysql-5.7.18/ mysql
mkdir mysql/mysql-files
chmod 750 mysql/mysql-files
chown -R mysql:mysql mysql-5.7.18/
cd mysql
會在mysql目錄內生成一個data目錄,存放數(shù)據(jù)庫的目錄
bin/mysqld --initialize --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data
返回結果最后一行的末尾有隨機密碼,我的記下來:wa0I:1w?V--a
2017-04-28T02:49:00.853710Z 1 [Note] A temporary password is generated for root@localhost: wa0I:1w?V--a
想設置默認密碼為空則將--initialize選項替換為--initialize-insecure選項
bin/mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data
bin/mysql_ssl_rsa_setup --datadir /application/mysql/data/
指定data目錄的路徑
chown -R root .
chown -R mysql data mysql-files
除了mysql目錄下的data目錄和mysql-files目錄所屬用戶不變,其他所有文件的所屬用戶改為root
sed -i 's/^datadir=\/var\/lib\/mysql/datadir=\/application\/mysql\/data/g' /etc/my.cnf
sed -i 's/^socket=\/var\/lib\/mysql\/mysql.sock/socket=\/tmp\/mysql.sock/g' /etc/my.cnf
sed -i 's/^log-error=\/var\/log\/mariadb\/mariadb.log/log-error=\/application\/mysql\/data\/err.log/g' /etc/my.cnf
sed -i 's/^pid-file=\/var\/run\/mariadb\/mariadb.pid/pid-file=\/application\/mysql\/data\/mysql.pid/g' /etc/my.cnf
等價于:
vi /etc/my.cnf
datadir=/application/mysql/data
socket=/tmp/mysql.sock
log-error=/application/mysql/data/err.log
pid-file=/application/mysql/data/mysql.pid
/etc/my.cnf Content:
[mysqld]
datadir=/application/mysql/data
socket=/tmp/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/application/mysql/data/err.log
pid-file=/application/mysql/data/mysql.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
cp support-files/mysql.server /etc/init.d/mysql
將mysql的啟動程序拷貝到/etc/init.d/目錄下,以便啟動程序
方法一:
思路是給配置文件提供的變量進行賦值。較麻煩。
sed -i 's/^basedir=/basedir=\/application\/mysql/g' /etc/init.d/mysql
sed -i 's/^datadir=/datadir=\/application\/mysql\/data/g' /etc/init.d/mysql
sed -i 's/^mysqld_pid_file_path=/mysqld_pid_file_path=\/application\/mysql\/data\/mysql.pid/g' /etc/init.d/mysql
等價于將45、46兩行
basedir=
datadir=
mysqld_pid_file_path=
替換成
basedir=/application/mysql
datadir=/application/mysql/data
mysqld_pid_file_path=/application/mysql/data/mysql.pid
方法二(推薦):
思路是將腳本的默認地址(/usr/local/mysql)直接替換成自定義路徑(/application/mysql),便不用給變量賦值
sed -i 's#/usr/local/mysql#/application/mysql#g' /etc/init.d/mysql
到這里mysql安裝完成可以正常啟動
將mysql命令創(chuàng)建軟鏈接到環(huán)境變量的目錄,使用戶可以在變量找到相應的命令
ln -s /application/mysql/bin/* /usr/local/sbin
[root@www mysql]# mysql -u root -p
Enter password: #輸入之前保存的隨機密碼drRR0<ZuDgX_
...
mysql> #成功登陸到mysql控制臺
mysql> alter user 'root'@'localhost' identified by 'NewPassWord';
#將密碼修改為NewPassWord
Query OK, 0 rows affected (0.01 sec) #修改成功
mysql> quit
Bye
[root@www mysql]#
or
mysql> ^DBye
[root@www mysql]#
mysql -u root -p
service mysql start
service mysql stop
service mysql restart
看了以上mysql-5.7.18自定義安裝路徑講義介紹,希望能給大家在實際運用中帶來一定的幫助。本文由于篇幅有限,難免會有不足和需要補充的地方,大家可以繼續(xù)關注億速云行業(yè)資訊板塊,會定期給大家更新行業(yè)新聞和知識,如有需要更加專業(yè)的解答,可在官網(wǎng)聯(lián)系我們的24小時售前售后,隨時幫您解答問題的。
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。