1.下載:
Wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.19-linux-g libc2.12-x86_64.tar.gz
2.解壓:
tar -xzvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ #將 文件解壓到指定目錄
3.移除安裝包
mv? mysql-5.7.19-linux-glibc2.12-x86_64 mysql
4.檢查庫文件是否有刪除,若有便刪除(linux系統(tǒng)自帶的)
rpm -qa | grep mysql
rpm -e –-nodeps mysql-libs-5.1.52.x86_64
rpm -e -nodeps mysql-libs-5.1.73-8.el6_8.x86_64
5.創(chuàng)建mysql組和用戶
groupadd mysql
useradd -r -g mysql mysql
6.在mysql下添加data目錄
mkdir data
7.更改mysql目錄下所有的目錄及文件夾所屬組合用戶
cd /usr/local/
chown -R mysql mysql/
chgrp -R mysql mysql/
cd mysql/
ls -l
8.安裝和初始化數(shù)據(jù)庫
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US
2017-08-31T09:00:54.941514Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-08-31T09:00:56.364312Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-08-31T09:00:56.602211Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-08-31T09:00:56.668145Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: e69986d2-8e2a-11e7-a335-
005056b427be.2017-08-31T09:00:56.671464Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-08-31T09:00:56.672453Z 1 [Note] A temporary password is generated for root@localhost:? qfuqvCsHb2!.
注意初始密碼:這里password is generated for root@localhost:? qfuqvCsHb2!.
9.配置my.cnf
進(jìn)入/usr/local/mysql/support-files/目錄下
查看是否存在my-default.cnf文件,如果存在直接copy到/cdf文 件中
cp -a ./support-files/my-default.cnf /etc/my.cnf
如果不存在my-default.cnf文件,則在/etc/目錄下創(chuàng)建my.cnf,并寫 入以下內(nèi)容
#[mysql]?
#basedir=/usr/local/mysql/?
#datadir=/usr/local/mysql/data/
10.啟動(dòng)服務(wù):
cd bin/
./mysqld_safe --user=mysql &
Logging to '/var/log/mysql/mysql.log'.
11.查看mysql服務(wù):
ps -ef|grep mysql
12.將mysqld服務(wù)加入開機(jī)自啟動(dòng)項(xiàng):
將{mysql}/ support-files/mysql.server 拷貝為/etc/init.d/mysql并設(shè) 置運(yùn)行權(quán)限,這樣就可以使用service mysql命令啟動(dòng)/停止服務(wù),
否則就只能使用{mysql}/bin/mysqld_safe &命令來啟動(dòng)服務(wù)
還需要把mysql.server中basedir的相關(guān)路徑,改為自定義的路徑, 默認(rèn)路徑是/usr/local/mysql
cp mysql.server /etc/init.d/mysql?
chmod +x /etc/init.d/mysql
-- 把mysql注冊為開機(jī)啟動(dòng)的服務(wù)
chkconfig --add mysql?
-- 查看是否添加成功
chkconfig --list mysql?
mysql? ? ? ? ? 0:off? 1:off? 2:on? ? 3:on? ? 4:on? ? 5:on? ? 6:off
13.啟動(dòng)服務(wù):
service mysql start
14.將mysql配置環(huán)境:
vi /etc/profile
export PATH=/usr/local/mysql/bin
15.登錄mysql:
mysql -uroot -p
密碼是第八步產(chǎn)生的密碼
quit或者exit退出mysql。
16.設(shè)置密碼:
set password=password("root");
Query OK, 0 rows affected, 1 warning (0.00 sec)
17.設(shè)置遠(yuǎn)程登錄權(quán)限:
grant all privileges on *.* to'賬號(hào)' @'%' identified by '遠(yuǎn)程登陸密碼 ';