下載
image.png
下載后將文件上傳到服務器镜沽,并賦予755可執(zhí)行權限
安裝
1、解壓
[root@localhost soft]# tar -xvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
復制解壓后的mysql目錄
[root@localhost soft]# cp -r mysql-5.7.23-linux-glibc2.12-x86_64 /usr/local/mysql
2关顷、添加用戶組和用戶
添加用戶組
[root@localhost soft]# groupadd mysql
添加用戶mysql且添加到用戶組mysql
[root@localhost soft]# useradd -g mysql mysql
3痕囱、安裝
安裝前需要卸載系統(tǒng)自帶的Mysql
- 檢測系統(tǒng)是否安裝:
[root@localhost soft]# rpm -qa | grep mysql
[root@localhost soft]# rpm -qa | grep mariadb
- 檢測到已安裝置逻,卸載之:
[root@localhost soft]# yum -y remove mysql*
[root@localhost soft]# yum -y remove mariadb*
- 安裝
注:mysql目錄下沒有data玩讳,需要手動創(chuàng)建
將mysql及其下所有的目錄所有者和組均設為mysql
[root@localhost soft]# cd /usr/local/mysql/
[root@localhost soft]# chown -R mysql:mysql *
- 初始化
[root@localhost soft]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
初始化成功信息如下所示:
2018-08-21T02:51:32.462338Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-08-21T02:51:32.970357Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-08-21T02:51:33.028257Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-08-21T02:51:33.035443Z 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: 1cb0d086-a4ed-11e8-a804-000c29fe8b9d.
2018-08-21T02:51:33.036418Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-08-21T02:51:33.037704Z 1 [Note] A temporary password is generated for root@localhost: 2balpgvBcf!1
注意最后一行呛牲,這也是和之有版本不同的地方刮萌,它給了root一個初始密碼,后面要登錄的時候要用到這個密碼娘扩。
- 配置
[root@localhost soft]# vi /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
注意着茸,tmp目錄不存在,請自行創(chuàng)建畜侦。
4、配置環(huán)境變量
[root@localhost soft]# vi /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
[root@localhost soft]# source /etc/profile
5躯保、設置mysql以服務運行并且開機啟動
[root@localhost soft]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@localhost soft]# chmod +x /etc/init.d/mysql
設置開機啟動
[root@localhost soft]# chkconfig mysql on
6旋膳、啟動
[root@localhost soft]# service mysql start
7、修改密碼
方法一
mysql> update mysql.user set authentication_string=password('123456') where user='root' and Host = 'localhost';
mysql> flush privileges;
方法二
mysql> alter user 'root'@'localhost' identified by '123456';
mysql> flush privileges;
方法三
mysql> set password for 'root'@'localhost'=password('123456');
mysql> flush privileges;
8途事、開啟遠程訪問
[root@hadoop001 ~]# mysql -u root -p
mysql> use mysql;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
注:如果遠程無法訪問验懊,請檢查mysql端口是否被防火墻攔截
9、問題
配置完出現(xiàn)如下問題
image.png
解決:
初始化的時候有個密碼尸变,只是相當于臨時密碼义图,直接執(zhí)行設置密碼即可:
alter user user() identified by "root";