一、軟件包下載地址:https://downloads.mysql.com/archives/community/
二、新建目錄/tools/soft 目錄並重名mysql
mkdir -p /tools/soft
#解壓到安裝目錄
tar -zxvf /tools/soft/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz -C /tools/
#將文件重名稱
mv /tools/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz mysql
三、創建mysql用戶組和用戶並修改權限
groupadd mysql
useradd -r -g mysql mysql
四、創建數據目錄並賦予權限
mkdir -p /data/mysql #創建目錄
chown mysql:mysql -R /data/mysql #賦予權限
五、配置my.cnf
vim /etc/my.cnf
按下i鍵貼內容如下
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/tools/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true
按:wq保存
六、初始化數據庫
#進入安裝目錄
cd /tools/mysql/bin/
#初始化
./mysqld --defaults-file=/etc/my.cnf --basedir=/tools/mysql/ --datadir=/data/mysql/ --user=mysql --initialize
#查看密碼
[root@miguvideo-3 soft]# cat /data/mysql/mysql.err
2020-04-23T08:47:08.671449Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-04-23T08:47:08.763758Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-04-23T08:47:08.835429Z 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: 0436c78a-853f-11ea-888d-fa163e1ced08.
2020-04-23T08:47:08.839632Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-04-23T08:47:08.840339Z 1 [Note] A temporary password is generated for root@localhost: L>ysxdro!4BX
#初始密碼爲L>ysxdro!4BX
七、啓動mysql,並更改root 密碼
#先將mysql.server放置到/etc/init.d/mysql中
cp /tools/mysql/support-files/mysql.server /etc/init.d/mysql
#ps:很重的一步直接執行service mysql start啓動報錯 mysqld_safe The file /usr/local/mysql/bin/mysqld does not exist or is not executable解決辦法如下 https://www.cnblogs.com/wajika/p/6719805.html 創建鏈接
ln -s /tools/mysql/bin/mysqld /usr/local/mysql/bin/mysqld
#啓動mysql
service mysql start
#查看是否啓動
ps -ef|grep mysql
#添加mysql環境變量
vi /etc/profile
添加如下代碼
export MYSQL_HOME=/tools/mysql
export PATH=$PATH:$MYSQL_HOME/bin
#保存
:wq
#更新環境變量
source /etc/profile
#修改用戶名密碼
[root@miguvideo-3 soft]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.17 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
執行下面三部
SET PASSWORD = PASSWORD('123456');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES;
#密碼修改成功~~
#修改任何地址都能訪問
use mysql #訪問mysql庫
update user set host = '%' where user = 'root'; #使root能再任何host訪問
FLUSH PRIVILEGES; #刷新