一 安装环境node
(1)CentOS版本:CentOS-7mysql
查看方法:linux
[root@bogon 桌面]# cat /etc/redhat-releasesql
CentOS Linux release 7.0.1406 (Core)数据库
来源:官网下载centos
下载地址:http://www.centos.org/服务器
(2)MySQL版本:MySQL-5.6.22oracle
来源:官网下载工具
下载地址:https://edelivery.oracle.com/EPD/Search/handle_go测试
或者http://pan.baidu.com/s/1dDu6n9R
名称:MySQL Database 5.6.22 RPM for Oracle Linux / RHEL 7 x86 (64bit)
在网上搜了一下,Linux下安装MYSQL有三种方式:
1 经过yum命令在线下载安装
yum install mysql-devel
2 下载离线rpm安装包安装
3 下载源码编译安装
方式1不打算用,由于咱们大部分项目服务器是不能直接上Internet的,网上关于在线安装的教程不少,方式3对于只要应用MYSQL的人来讲不必画蛇添足。
1. 解压下载的zip包,会发现有如下几个rpm包:
MySQL-client-advanced-5.6.22-1.el7.x86_64.rpm
MySQL-devel-advanced-5.6.22-1.el7.x86_64.rpm
MySQL-embedded-advanced-5.6.22-1.el7.x86_64.rpm
MySQL-server-advanced-5.6.22-1.el7.x86_64.rpm
MySQL-shared-advanced-5.6.22-1.el7.x86_64.rpm
MySQL-shared-compat-advanced-5.6.22-1.el7.x86_64.rpm
MySQL-test-advanced-5.6.22-1.el7.x86_64.rpm
2. 卸载MariaDB
若是直接点击rpm包安装会获得错误提示。由于CentOS的默认数据库已经再也不是MySQL了,而是MariaDB,为何呢?
MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL受权许可。开发这个分支的缘由之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,所以社区采用分支的方式来避开这个风险。MariaDB的目的是彻底兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。
查看当前安装的mariadb包:
[root@bogon 桌面]# rpm -qa | grep mariadb
将它们通通强制性卸载掉:
[root@bogon 桌面]# rpm -e --nodeps mariadb-libs-5.5.35-3.el7.x86_64
[root@bogon 桌面]# rpm -e --nodeps mariadb-5.5.35-3.el7.x86_64
[root@bogon 桌面]# rpm -e --nodeps mariadb-server-5.5.35-3.el7.x86_64
3. 安装MYSQL
双击下面三个包进行自动安装:
MySQL-client-advanced-5.6.22-1.el7.x86_64.rpm
MySQL-devel-advanced-5.6.22-1.el7.x86_64.rpm
MySQL-server-advanced-5.6.22-1.el7.x86_64.rpm
提示:其实第二个包devel我也不知道是干什么的,也不知道是否是必须的(上网搜了一下应该不是必须的),没有测试是否必须就已经点来装上了,也不想花时间去测试是否必须了,有测试过的朋友麻烦留言告知。
4. 启动MYSQL
[root@bogon 桌面]#service mysql start
获得错误:ERROR!The server quit without updating PID file
咱们这里主要是由于:selinux惹的祸,若是是centos系统,默认会开启selinux。解决方法是关闭它,打开/etc/selinux/config,把SELINUX=enforcing改成SELINUX=disabled后存盘退出重启机器。
而后再启动mysql就没问题了:
[root@bogon 桌面]#service mysql start
查看MySQL运行状态:
[root@bogon 桌面]# service mysql status
SUCCESS! MySQL running (2377)
5. 默认root用户登陆MYSQL
[root@bogon 桌面]# mysql -u root -p
Enter password:
ERROR 1045 (28000):Access denied for user 'root'@'localhost' (using password: YES)
发现有有错误,而后在网上查了一下说使用下面命令修改root初始化密码:
[root@bogon 桌面]# /usr/bin/mysqladmin -u root password 'passok'
/usr/bin/mysqladmin: connect to server at'localhost' failed
error: 'Accessdenied for user 'root'@'localhost' (using password: NO)'
发现MYSQL数据库默认的root用户仍是没办法设置密码进行登陆,须要作一下操做:
最近新装好的mysql在进入mysql工具时,老是有错误提示:
# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
使用网上介绍的方法修改root用户的密码:
# mysqladmin -uroot -p password 'newpassword'
Enter password:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'
如今终于被我找到了解决方法,以下(请先测试方法三,谢谢!):
方法一:
# /etc/init.d/mysql stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
重置MySQL中root用户密码及验证
仍是不行,而后在网上又找到一个重置MySQL中root用户密码及验证的方法:
(1) 中止MySQL服务
[root@bogon 桌面]# service mysql stop
Shutting down MySQL.. SUCCESS!
(2) 输入绕过密码认证命令
[root@bogon 桌面]# mysqld_safe --user=mysql --skip-grant-tables--skip-networking &
执行上面命令后,此会话窗口会出现无反应的状态,须要使用CTRL+C中断会话,检查/var/lib/mysql/DB-Server.err日志,发现也无其它异常信息。没有弄明白该会话窗口为啥会出现无响应状态。
接着
mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.19 MySQL Community Server (GPL)
Copyright (c) 2000, 2014, 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> select Host, User, Password,password_expired
-> from user
-> where user='root' and host='root' or host='localhost';
+-----------+------+-------------------------------------------+------------------+
| Host | User | Password | password_expired |
+-----------+------+-------------------------------------------+------------------+
| localhost | root | *A848DE7CCD839E924921BEE41711991DDA0D529E | Y |
+-----------+------+-------------------------------------------+------------------+
1 row in set (0.00 sec)
mysql> update user set password=PASSWORD('p12#456')
-> where user='root' and host='root' or host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
新设置用户或更改密码后需用flush privileges刷新MySQL的系统权限相关表,不然会出现拒绝访问,还有一种方法,就是从新启动mysql服务器,来使新设置生效。
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
[root@DB-Server init.d]# /etc/rc.d/init.d/mysql restart
Shutting down MySQL..140722 15:02:27 mysqld_safe mysqld from pid file /var/lib/mysql/DB-Server.pid ended
[ OK ]
Starting MySQL.[ OK ]
[2]- Done mysqld_safe --user=mysql --skip-grant-tables --skip-networking
[root@DB-Server init.d]# mysql -u root p
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@DB-Server init.d]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.19
Copyright (c) 2000, 2014, 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数据库后执行脚本遭遇 ERROR 1820 (HY000): You must SET PASSWORD before executing this statement,能够使用从新设置一次密码便可解决问题.
mysql>set password = password('p12#456');