Centos7 Mysql5.7.27二進制安裝


步驟一:下載安裝包,打開Mysql官網,找到對應的

下載路徑如下:https://downloads.mysql.com/archives/community/

wget https://downloads.mysql.com/archives/get/file/mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz  -O /usr/local/src/mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz

 

步驟二:下載依賴包,Centos7自帶不需要安裝

 

[root@centos702 21:56:19]:/usr/local/src
#yum -y install libaio
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
軟件包 libaio-0.3.109-13.el7.x86_64 已安裝並且是最新版本
無須任何處理

步驟三:解壓安裝包

[root@centos702 21:58:45]:/usr/local/src
#tar -zxvf mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz 

步驟四:創建數據庫用戶,移動數據庫文件到你想要放的位置,並創建mysql數據目錄,最后修改屬主為Mysql

[root@centos702 21:59:26]:/usr/local/src
#useradd -M -s /sbin/nologin -r mysql
#mv /usr/local/src/mysql-5.7.27-linux-glibc2.12-x86_64 /home/data/mysql [root@centos702
22:02:09]:/usr/local/src #mkdir -p /home/data/mysql [root@centos702 22:02:18]:/usr/local/src #chown -R mysql.mysql /home/data/mysql

步驟五:初始化數據庫

[root@centos702 22:04:56]:/home/data
#/home/data/mysql/bin/mysqld --initialize --user=mysql --basedir=/home/data/mysql --datadir=/home/data/mysql/data
2019-11-09T14:06:56.634380Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-11-09T14:06:57.063698Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-11-09T14:06:57.142365Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-11-09T14:06:57.200813Z 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: 30cc7a37-02fa-11ea-a548-000c29cbc202.
2019-11-09T14:06:57.202254Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-11-09T14:06:57.203612Z 1 [Note] A temporary password is generated for root@localhost: KaELVb2yol<4 #此次是生成的臨時密碼,用於第一次登陸,登陸后需要重新修改

步驟六:創建配置文件,這里只創建常見配置文件

cat > /etc/my.cnf <<EOF
[mysqld]
basedir=/home/data/mysql
datadir=/home/data/mysql/data
port=3306
socket=/home/data/mysql/mysql.sock
character-set-server=utf8
log-error=/var/log/mysqld.log
pid-file=/tmp/mysqld.pid
[mysql]
socket=/home/data/mysql/mysql.sock
[client]
socket=/home/data/mysql/mysql.sock
EOF

步驟七:配置環境變量,並刷新

cat >/etc/profile.d/mysql.sh <<EOF
export PATH=/home/data/mysql/bin:\$PATH
EOF
source /etc/profile.d/mysql.sh

步驟八:生成啟動腳本,並啟動mysql

[root@centos702 22:14:40]:/home/data
#cp /home/data/mysql/support-files/mysql.server /etc/init.d/mysql
[root@centos702 22:16:42]:/home/data
#chmod +x /etc/init.d/mysql
[root@centos702 22:17:55]:/home/data #vim /etc/init.d/mysql
#修改mysql啟動配置文件,指定datadir和basedir路徑,如不指定,默認是/usr/local/mysql
[root@centos702 22:18:31]:/home/data
#sed -i '46s#basedir=#basedir=/home/data/mysql#' /etc/init.d/mysql 
[root@centos702 22:20:15]:/home/data
#sed -n '46p' /etc/init.d/mysql 
basedir=/home/data/mysql
[root@centos702 22:20:30]:/home/data
#sed -i '47s#datadir=#datadir=/home/data/mysql/data#' /etc/init.d/mysql 
[root@centos702 22:21:13]:/home/data
#sed -n '47p' /etc/init.d/mysql 
datadir=/home/data/mysql/data
#啟動mysql
[root@centos702 22:23:54]:/home/data
# /etc/init.d/mysql start
Starting MySQL. SUCCESS! 

步驟九:登錄mysql,並修改密碼

[root@centos702 22:26:28]:/home/data
#mysql -uroot -p'KaELVb2yol<4'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.27

Copyright (c) 2000, 2019, 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 for root@localhost=password('cnhope');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

 

 

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM