#将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
复制代码