#將mysql目錄訪問權限賦爲myql用戶
[root@VM_0_17_centos mysql57]# chown -R mysql /usr/mysql/mysql57
#改變mysql目錄的用戶組屬於mysql組
[root@VM_0_17_centos mysql57]# chgrp -R mysql /usr/mysql/mysql57
#查看mysql目錄下全部的目錄及文件夾所屬組合用戶
[root@VM_0_17_centos mysql57]# cd /usr/mysql/mysql57
[root@VM_0_17_centos mysql57]# ll
total 56
drwxr-xr-x 2 mysql mysql 4096 Aug 11 21:24 bin
-rw-r--r-- 1 mysql mysql 17987 Dec 28 2017 COPYING
drwxr-xr-x 2 mysql mysql 4096 Aug 11 21:40 data
drwxr-xr-x 2 mysql mysql 4096 Aug 11 21:24 docs
drwxr-xr-x 3 mysql mysql 4096 Aug 11 21:23 include
drwxr-xr-x 5 mysql mysql 4096 Aug 11 21:24 lib
drwxr-xr-x 4 mysql mysql 4096 Aug 11 21:23 man
-rw-r--r-- 1 mysql mysql 2478 Dec 28 2017 README
drwxr-xr-x 28 mysql mysql 4096 Aug 11 21:24 share
drwxr-xr-x 2 mysql mysql 4096 Aug 11 21:24 support-files
複製代碼
權限被修改
==配置mysql==(重點部分)
建立如下文件,設置訪問權限,用於mysql配置中
第一步:==建立文件/tmp/mysql.sock==。並設置權限
建立文件
[root@VM_0_17_centos mysql57]# mkdir tmp
[root@VM_0_17_centos mysql57]# cd tmp
[root@VM_0_17_centos tmp]# ll
total 0
[root@VM_0_17_centos tmp]# touch mysql.sock
[root@VM_0_17_centos tmp]# ll
total 0
-rw-r--r-- 1 root root 0 Aug 11 21:59 mysql.sock
複製代碼
[root@VM_0_17_centos mysql57]# ps -ef |grep mysql
複製代碼
第一我沒有成功,由於我有個地方出問題了。我在方式二配置成功。
方式二 配置mysql自動啓動(可根據須要配置)
[root@VM_0_17_centos mysql57]# cp support-files/mysql.server /etc/init.d/mysql
[root@VM_0_17_centos mysql57]# vim /etc/init.d/mysql
複製代碼
添加配置(i 進入編輯;esc--> :wq保存退出)
若配置了mysql自啓動方式則可使用服務方式啓動mysql
#查看mysql狀態
/etc/init.d/mysql status 或者 service mysql status
#啓動mysql
/etc/init.d/mysql start 或者 service mysql start
#中止mysql
/etc/init.d/mysql stop 或者 service mysql stop
#從新啓動mysql
/etc/init.d/mysql restart 或者 service mysql restart
查看mysql服務說明啓動成功
ps -ef|grep mysql
啓動mysql
複製代碼
[root@VM_0_17_centos tmp]# service mysql start
複製代碼
Starting MySQL. ERROR! The server quit without updating PID file (/usr/local/mysql57/tmp/mysqld.pid). ==報錯了,上面說沒有/usr/local/mysql57/tmp/mysqld.pid。==
解決方案:
a) 建立文件/usr/local/mysql57/tmp/mysqld.pid
b) 修改權限
修改存放mysqld.pid文件目錄的權限
chown -R mysql /usr/local/mysql57/tmp
chgrp -R mysql /usr/local/mysql57/tmp
chmod 777 /usr/local/mysql57/tmp
複製代碼
[root@localhost bin]# ./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.21
Copyright (c) 2000, 2018, 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.
複製代碼
1.報錯
忽然報錯
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
複製代碼
mysql> use mysql
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
複製代碼
==解決方案:須要從新修改一下密碼==
mysql> alter user 'root'@'localhost' identified by '修改的密碼';
mysql> flush privileges;
mysql> quit;
複製代碼
2.繼續配置
mysql> use mysql;
#改表法
mysql> update user set host='%' where user='root';
#受權法
mysql> GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypwd' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
mysql> quit;
複製代碼
3.重啓mysql
[root@VM_0_17_centos bin]# service mysql restart;
##注意有的版本須要使用mysqld命令
[root@VM_0_17_centos bin]# /etc/init.d/mysqld restart
複製代碼
4.設置防火牆
a)配置防火牆開啓3306端口
[root@VM_0_17_centos bin]# /sbin/iptables -I INPUT -p tcp --dport 3306-j ACCEPT
[root@VM_0_17_centos bin]# /etc/rc.d/init.d/iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables: [ OK ]
[root@VM_0_17_centos bin]# /etc/rc.d/init.d/iptables restart
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]
複製代碼
b)臨時關閉防火牆
[root@VM_0_17_centos bin]# service iptables stop
複製代碼
c)永久關閉防火牆
重啓後永久生效
[root@VM_0_17_centos bin]# chkconfig iptables off
複製代碼