CentOS 6.5安装MySQL 5.6.10及安全配置(2)

注:由于MySQL在启动的时候,会先去/etc/my.cnf找配置文件,如果没有找到则搜索$basedir/my.cnf,也即/usr/local/mysql-5.6.10/my.cnf,所以必须确保/etc/my.cnf没有存在,否则可能导致无法启动。

实际操作上发现系统上存在该文件,所以这里可能需要将该文件先备份改名,然后再根据上面的配置写配置文件:

# mv /etc/my.cnf /etc/my.cnf.bak # vim /usr/local/mysql-5.6.10/my.cnf [mysqld] basedir=/usr/local/mysql-5.6.10 datadir=/data/mysql/data socket=/usr/local/mysql-5.6.10/tmp/mysql.sock user=mysql sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

修改MySQL用户root的密码,这里使用mysqld_safe安全模式启动:

# mysqld_safe --user=mysql --skip-grant-tables --skip-networking & [1] 3970 [root@iZ94mobdenkZ ~]# 141230 19:02:31 mysqld_safe Logging to '/data/mysql/data/centos.err'. 141230 19:02:32 mysqld_safe Starting mysqld daemon with databases from /data/mysql/data

这个时候已经启动了mysqd_safe安全模式,另开一个窗口作为客户端连入MySQL服务器:

# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.10 Source distribution Copyright (c) 2000, 2013, 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> use mysql; mysql> update user set password=password('yourpassword') where user='root'; mysql> flush privileges; mysql> exit;

修改完毕之后使用kill把mysqld_safe进程杀死:

# ps aux | grep mysql root 3970 0.0 0.2 106308 1492 pts/1 S 19:02 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --user=mysql --skip-grant-tables --skip-networking mysql 4143 0.1 18.0 558280 90316 pts/1 Sl 19:02 0:00 /usr/local/mysql-5.6.10/bin/mysqld --basedir=/usr/local/mysql-5.6.10 --datadir=/data/mysql/data --plugin-dir=/usr/local/mysql-5.6.10/lib/plugin --user=mysql --skip-grant-tables --skip-networking --log-error=/data/mysql/data/centos.err --pid-file=/data/mysql/data/centos.pid --socket=/usr/local/mysql-5.6.10/tmp/mysql.sock root 4313 0.0 0.1 103252 836 pts/0 S+ 19:05 0:00 grep mysql # kill -9 3970 # kill -9 4143

或者回到刚才启动mysqld_safe的窗口ctrl+c将进程杀死也行。

复制服务启动脚本:

# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld # chmod +x /etc/init.d/mysqld

设置开机启动MySQL服务并正常开启MySQL服务(非必要项):

# chkconfig mysqld on # service mysqld Usage: mysqld {start|stop|restart|reload|force-reload|status} [ MySQL server options ] # service mysqld start Starting MySQL.

以后就可以直接通过service mysqld命令来开启/关闭MySQL数据库了。

最后,建议生产环境下运行安全设置脚本,禁止root用户远程连接,移除test数据库和匿名用户等:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/820012d50fd56779d1b429d0052d138d.html