Linux 安裝MySQL5.7


1、mysql 5.7 下載鏈接

 2、上傳到服務器並解壓

[root@xiaobing software]# ls
jdk1.8  mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
//解壓
[root@xiaobing software]# tar -zxvf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
//重命名
[root@xiaobing software]# mv mysql-5.7.34-linux-glibc2.12-x86_64 mysql

3、創建mysql用戶組和用戶並修改權限

[root@xiaobing mysql]# groupadd mysql
[root@xiaobing mysql]# useradd -r -g mysql mysql

4、創建數據目錄並賦予權限

[root@xiaobing software]# mkdir -p  /data/mysql
[root@xiaobing software]# chown mysql:mysql -R /data/mysql
[root@xiaobing data]# ll
total 0
drwxr-xr-x 2 mysql mysql 6 Jan 6 20:28 mysql

5、配置my.cnf

vim /etc/my.cnf  //內容如下:
[root@xiaobing etc]# ls | find 'my.cnf'
my.cnf
[root@xiaobing etc]# cat my.cnf 
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/software/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
[root@xiaobing etc]# 

6、初始化數據庫

//進入mysql的bin目錄
cd /usr/local/software/mysql/bin
//初始化
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize
//查看密碼
[root@xiaobing bin]# cat /data/mysql/mysql.err

 7、啟動mysql,並更改root 密碼,先將mysql.server放置到/etc/init.d/mysql中

[root@xiaobing support-files]# cp /usr/local/software/mysql/support-files/mysql.server /etc/init.d/mysql

8.報錯:

 修改下指定路徑:

[root@xiaobing init.d]# vim mysql
basedir=/usr/local/software/mysql
datadir=/data/mysql

9、啟動mysql

[root@xiaobing init.d]# service mysql start
Starting MySQL.                                            [  OK  ]
//到這里說明mysql已經安裝成功了!!

10、修改mysql 登錄密碼

 //bin目錄下執行
[root@xiaobing bin]# ./mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.34

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> 
                           

11、使用新密碼,重新登錄

[root@xiaobing bin]# ./mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> 
mysql> 
mysql> 
mysql> 
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> 

12、但是現在遠程鏈接還是不支持

//這里主要執行下面三個命令(先登錄數據庫)
use mysql                                            #訪問mysql庫
update user set host = '%' where user = 'root';      #使root能再任何host訪問
FLUSH PRIVILEGES;                                    #刷新

13.到此 MySQL5.7就裝好了,親測總結,以備后續參考!


免責聲明!

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



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