Center OS 離線安裝Mysql5.7

1.相關資料準備

1.離線安裝包下載

 

或者百度網盤

 鏈接:https://pan.baidu.com/s/1oVP3u8GSaavxoJqKnvZPKg 
提取碼:vw88

2.libao庫文件下載

鏈接:https://pan.baidu.com/s/12hrQIEF3kk2h2HlWE41G7w 
提取碼:fvt8

2.開始安裝

檢查MySQL是否已經安裝

rpm -qa | grep mysql
檢查mysql組和用戶是否存在,如無則創建
cat /etc/group | grep mysql
cat /etc/passwd | grep mysql 

 創建mysql組和用戶

 創建mysql用戶組
groupadd mysql

 創建一個用戶名爲mysql的用戶,並加入mysql用戶組 

useradd -g  mysql mysql

 將文件上傳到/usr/local/下 解壓並修改文件名稱爲mysql

tar -zxvf mysql-5.7.29-el7-x86_64.tar.gz 
mv mysql-5.7.29-el7-x86_64 mysql

 更改所屬的組和用戶

chown -R mysql mysql/
chgrp -R mysql mysql/

在mysql文件下創建一個 data文件

mkdir data

在/etc下創建my.cnf文件內容如下

[mysql]
socket=/var/lib/mysql/mysql.sock
# set mysql client default chararter
default-character-set=utf8

[mysqld]
socket=/var/lib/mysql/mysql.sock
# set mysql server port  
port = 3306 #默認是3306,這裏發現3306已經被佔用,因此防止這種情況發生,可以避免使用3306mysql默認端口
# set mysql install base dir
basedir=/usr/local/mysql
# set the data store dir
datadir=/usr/local/mysql/data
# set the number of allow max connnection
max_connections=200
# set server charactre default encoding
character-set-server=utf8
# the storage engine
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
explicit_defaults_for_timestamp=true

[mysql.server]
user=mysql
basedir=/usr/local/mysql

進入mysql 文件夾 安裝mysql,在安裝前安裝libao庫,不然會報錯,下載上面libao庫文件 並上傳到服務器上,執行以下命令安裝

rpm -ivh libaio-0.3.107-10.el6.x86_64.rpm

初始化安裝mysql

 bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

 設置文件目錄權限

cp ./support-files/mysql.server /etc/init.d/mysqld
 chown 777 /etc/my.cnf
chmod +x /etc/init.d/mysqld
chown -R mysql:mysql data

啓動mysql

/etc/init.d/mysqld restart

啓動如報以下錯誤,解決方式:https://blog.csdn.net/qq_32331073/article/details/76229420

[root@iZa7l05natlzu8lb3a8xebZ mysql]# /etc/init.d/mysqld restart
MySQL server PID file could not be found!                  [FAILED]
Starting MySQL.Logging to '/usr/local/mysql/data/iZa7l05natlzu8lb3a8xebZ.err'.
2020-04-30T04:41:34.421721Z mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists.
The server quit without updating PID file (/usr/local/mysql[FAILED]a7l05natlzu8lb3a8xebZ.pid).
[root@iZa7l05natlzu8lb3a8xebZ mysql]# mkdir   /var/lib/mysql
[root@iZa7l05natlzu8lb3a8xebZ mysql]# chmod 777  /var/lib/mysql

設置開機啓動

[root@iZa7l05natlzu8lb3a8xebZ mysql]# chkconfig --level 35 mysqld on
[root@iZa7l05natlzu8lb3a8xebZ mysql]# chkconfig --list mysqld

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
[root@iZa7l05natlzu8lb3a8xebZ mysql]# chmod +x /etc/rc.d/init.d/mysqld
[root@iZa7l05natlzu8lb3a8xebZ mysql]# chkconfig --add mysqld
[root@iZa7l05natlzu8lb3a8xebZ mysql]# chkconfig --list mysqld

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
[root@iZa7l05natlzu8lb3a8xebZ mysql]# 

配置mysql的環境變量

vim /etc/profile
修改/etc/profile,在最後添加如下內容
# 修改/etc/profile文件
#set mysql environment
export PATH=$PATH:/usr/local/mysql/bin
# 使文件生效
source /etc/profile

獲取mysql初始密碼

cat /root/.mysql_secret  

登錄mysql 修改密碼

[root@iZa7l05natlzu8lb3a8xebZ mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.29

Copyright (c) 2000, 2020, 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('Ycyztb#2019');
Query OK, 0 rows affected, 1 warning (0.00 sec)

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

mysql> 

添加遠程訪問權限

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select host,user from user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| %         | root          |
| localhost | mysql.session |
| localhost | mysql.sys     |
+-----------+---------------+
3 rows in set (0.00 sec)

mysql> 

重啓mysql生效配置

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章