最近开始使用MySQL进行一些小网站的开发,所以找了一些资料进行安装,不过安装之后有些东西使用的不方便,消耗了好多的时间,所以我也把我遇到的一些问题及解决方案整理出来,非常感谢参考资料中的共享者们。
1. 安装步骤
Step1: 检测系统是否自带安装mysql
Step2: 删除系统自带的mysql及其依赖#yum list installed | grep mysql
Step3: 给CentOS添加rpm源,并且选择较新的源# yum -y remove mysql-libs.x86_64
Step4:安装mysql 服务器</pre><pre name="code" class="python">#wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm #yum localinstall mysql-community-release-el6-5.noarch.rpm # yum repolist all | grep mysql # yum-config-manager --disable mysql55-community # yum-config-manager --disable mysql56-community # yum-config-manager --enable mysql57-community-dmr # yum repolist enabled | grep mysql
Step5: 启动mysql# yum install mysql-community-server
Step6: 查看mysql是否自启动,并且设置开启自启动#service mysqld start
Step7: mysql安全设置# chkconfig --list | grep mysqld # chkconfig mysqld on
注:我在第七步上设置root用户密码时,一直报下面的错误,所以我在后面提到修改root的密码,因为密码设置一直失败# mysql_secure_installation
ERROR 1045 (28000): Access denied for user 'myweb'@'localhost' (using password: NO)
2. 常用设置
mysql的默认配置文件一般在这几个文件里[/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf ]
在设置root密码时也经过一番周折,总结出一个最简单的方法,那就是直接到mysql的用户数据库里修改密码。大家可以点击这里查看配置文件中各项说明
密码修改
修改密码时一直报错: ERROR 1819 (HY000): Your password does NOT satisfy the CURRENT policy requirements。 是因为MySQL5.6.6增加了密码强度验证插件validate_password,相关参数设置的较为严格,所以……
关于插件的配置信息,可以点击这里查看,这位同学写的很全面
通过以下命令参数修改配置文件,然后重启服务即可
# plugin env plugin-load=validate_password.so validate-password=OFF # ON/OFF/... 设置为关闭
使用免密码方式登录到mysql命令行窗口
登录后修改密码[root@iZ250x18mnzZ myweb]# mysqld_safe --skip-grant-tables & [1] 26390 [root@iZ250x18mnzZ myweb]# 2016-03-09T13:52:36.487526Z mysqld_safe Logging to '/var/log/mysqld.log'. 2016-03-09T13:52:36.519635Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql [root@iZ250x18mnzZ myweb]# [root@iZ250x18mnzZ myweb]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.11 MySQL Community Server (GPL) Copyright (c) 2000, 2016, 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>
上网搜了好多资料,大部分修改密码都是这么修改mysql> update mysql.user set authentication_string=PASSWORD('password') where user='root' and host='localhost'; Query OK, 1 row affected, 1 warning (0.05 sec) Rows matched: 1 Changed: 1 Warnings: 1 mysql> flush privileges; Query OK, 0 rows affected (0.03 sec)
update mysql.user set PASSWORD=PASSWORD('passwor') where user='root' and host='localhost';
但是实际上mysql5.7的数据库中,user根本没有password字段。
root免密码登录
在公司的服务器上操作mysql时,直接在shell中输入mysql就可以直接登录到mysql命令操作中,而我在机器上安装后却需求mysql -u root -p 然后输入密码才能登录,找了一些资料,找到一个比较简单的,那就是直接将root的密码设置为空就可以。
在mysql5.6以上有个密码格式校验的插件,默认就已经安装上了,所以我当时改密码的时候一直是密码格式不对,我们按照上面的操作,把密码格式校验插件去掉,再按照我下面的操作就可以修改密码为空了,然后就可以很简单的使用mysql直接进入命令操作,这样虽然是简单,但是也相对的不够安全,在网上看到一个资料,是在配置文件配置好用户名和密码,有兴趣的同学可以点击这里。
设置密码为空操作步骤
mysql> update mysql.user set authentication_string=PASSWORD('') where user='root' and host='localhost'; Query OK, 0 rows affected (0.00 sec) Rows matched: 1 Changed: 0 Warnings: 0 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql>