1. 程式人生 > >linux 下普通使用者/(非root)下安裝mysql

linux 下普通使用者/(非root)下安裝mysql

1.準備好安裝包 上傳更目錄

本文基於mysql 5.7.22

2.

編輯my.cnf配置檔案,放在當前mysql安裝目錄下,配置檔案路徑/home/2iuser/mysql/my.cnf 。

[client]   
port=3306  
socket=/home/[client]   
port=3306  
socket=/home/whr/mysql/mysql.sock  

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

3.進入mysql目錄,開始安裝mysql。

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

4.啟動

bin/mysqld_safe  --defaults-file=/home/whr/mysql/my.cnf  --user=root &

5.獲取密碼

cat error.log | grep [email protected]

6.登陸

bin/mysql -u root -p -S /home/whr/mysql/mysql.sock

7.修改密碼

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
flush privileges;

8.設定遠端訪問

grant all PRIVILEGES on *.* to [email protected]'%'  identified by 'root的密碼';
flush privileges;

ps:

1.啟動如果報錯

121206 11:14:09 [ERROR] Can't start server: Bind on TCP/IP port: Address already in use
121206 11:14:09 [ERROR] Do you already have another mysqld server running on port: 3306 ?

解決:

ps aux |grep mysq*

檢視程序,然後全部kill掉,重試。

2.多注意情動方式,必須制定sock目錄