linux非root用戶安裝5.7.27版本mysql


  先下安裝包,到mysql官網https://dev.mysql.com/downloads/mysql/選好安裝包版本、操作系統類型(默認是最新版本,點擊右邊鏈接Looking for previous GA versions?進行自選):

 

 

  下完安裝包mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz后,通過rz上傳至linux的wlf用戶soft目錄下,並解壓:

$ cd soft
$ rz
$ cd ..
$ tar zxvf soft/mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz

  創建軟連接:

$ ln -s mysql-5.7.27-linux-glibc2.12-x86_64 mysql

  進入軟連接目錄:

$ cd mysql

  通過vi新增mysql配置文件my.cnf,內容如下:

[client]   
port=3336  
socket=/home/wlf/mysql/mysql.sock  

[mysqld]
port=3336
basedir=/home/wlf/mysql
datadir=/home/wlf/mysql/data
pid-file=/home/wlf/mysql/mysql.pid
socket=/home/wlf/mysql/mysql.sock
log_error=/home/wlf/mysql/error.log
server-id=100

  安裝mysql:

$ bin/mysqld --defaults-file=/home/wlf/mysql/my.cnf --initialize --user=wlf --basedir=/home/wlf/mysql --datadir=/home/wlf/mysql/data

  啟動mysql:

$ bin/mysqld_safe --defaults-file=/home/wlf/mysql/my.cnf  --user=wlf &
[1] 1253
$ 2019-09-20T04:16:20.253918Z mysqld_safe Logging to '/home/wlf/mysql/error.log'.
2019-09-20T04:16:20.292670Z mysqld_safe Starting mysqld daemon with databases from /home/wlf/mysql/data

  克隆會話打開另一個窗口,進入wlf用戶的mysql目錄,獲取密碼:

$ cat error.log | grep root@localhost
2019-09-20T03:47:05.657319Z 1 [Note] A temporary password is generated for root@localhost: 6)j;ng7%-(SP

  登陸mysql:

$ bin/mysql -u root -p
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

  不存在/tmp/mysql.sock,我們在my.cnf配置的mysql.sock路徑是/home/wlf/mysql/mysql.sock,所以當mysql去找這個文件時,我們讓它換個地方去找:

ln -s /home/wlf/mysql/mysql.sock /tmp/mysql.sock

  再次登錄,輸入之前拿到的密碼6)j;ng7%-(SP后登陸成功:

$ bin/mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
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> 

  我們修改下密碼:

mysql> set password for 'root'@'localhost' = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

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

  打完收工。如果不想用root用戶,而是新建自己的用戶,參見5.7.27版本mysql新增用戶

 


免責聲明!

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



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