一、下載mysql
打開 http://dev.mysql.com/downloads/mysql/ linux
選擇 linux - Generic,選擇對應的操做系統版本,sql
獲得mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz數據庫
二、傳資源vim
使用filezilla工具將壓縮包上傳linux,使用secureCRT鏈接linux並安裝。bash
1.解壓tar包ide
cd /software工具
tar -xzvf tar -xzvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gzui
mv tar -xzvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz mysqlurl
2.添加用戶與組
groupadd mysql
useradd -r -g mysql mysql
chown -R mysql:mysql mysql
3.建立data目錄(很重要!)
mkdir /usr/local/mysql/data
5.初始化數據,記住初始化密碼
[root@localhost mysql] ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
6.複製配置文件my-default.cnf、mysql.server到/etc
cp -a ./support-files/my-default.cnf /etc/my.cnf (選擇y)
cp -a ./support-files/mysql.server /etc/init.d/mysqld
修改my.cnf文件 (vim /etc/my.cnf)
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
7.啓動mysql
service mysqld start
查看初始化自動生成的密碼: cat /root/.mysql_secret (記住並複製下來,等會登錄mysql須要)
進入mysql:bin/mysql -uroot -p (把剛剛複製的密碼粘貼上來)
8.#登陸後重置root密碼
mysql> SET PASSWORD FOR 'root'@localhost = PASSWORD('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
9.#設置默認開機啓動
[root@localhost]# chkconfig --add mysqld
[root@localhost]# chkconfig --list mysqld
10.#設置遠程鏈接
進入數據庫
mysql> use mysql;
更改"mysql"數據庫裏的"user"表裏的"host"項,從"localhost"改稱"%"
mysql> update user set host = '%' where user ='root';
ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY' 不予理會
mysql> select host, user from user;
錯誤總結
2017-09-26 23:26:11 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2017-09-26 23:26:11 [ERROR] Can't locate the server executable (mysqld).
用戶運行無權限
su: warning: cannot change directory to /home/grid: No such file or directory
-bash-4.1$
新建用戶有問題,先建組再建用戶
刪除用戶
userdel mysql
groupdel mysql
usermod –G mysql mysql
沒法刪除用戶,提示進程佔用時,主目錄運行如下命令
vipw 用dd刪除須要刪除的用戶
vipw -s 用dd刪除須要刪除的用戶
再新增用戶和組
groupadd mysql
useradd -r -g mysql mysql
chown -R mysql:mysql mysql
su: warning: cannot change directory to /home/mysql: Permission denied
-bash: /home/mysql/.bash_profile: Permission denied
用戶主目錄所屬不對,用root用戶運行一下命令
[root@localhost ~]# chown -R mysql:mysql /home/mysql/
[root@localhost ~]# chmod -R 755 /home/mysql/
1045-access denied for user 'root'@
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root' @'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
mysql> flush privileges;
長時間鏈接不上,而且沒反應,嘗試關閉linux防火牆