不知道大家有没有同感,使用别的方式安装mysql不仅麻烦,而且经常遇到坑,建议大家安装和使用某种功能都参照官网说明
第一步:下载
下载MySQL5.7:http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar
第二步:安装
安装前检查服务器是否已安装MySQL,如已安装则将其卸载:
[root@worker1 tmp]# rpm -qa|grep mysql
mysql-libs-5.1.71-1.el6.x86_64
[root@worker1 tmp]# rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64 //卸载
解压下载的文件
[root@oracle11g-68 ~]# tar -xf mysql-5.7.27-1.el6.x86_64.rpm-bundle.tar
[root@oracle11g-68 ~]# ll
total 942416
-rw-r–r--. 1 root root 834 Aug 13 2018 70-persistent-cd.rules
-rw-r–r--. 1 root root 765 Sep 21 2018 70-persistent-net.rules
-rw-------. 1 root root 1485 Aug 13 2018 anaconda-ks.cfg
-rw-r–r--. 1 root root 482 Mar 27 2018 common.sh
drwxr-xr-x. 2 root root 4096 Aug 13 2018 Desktop
drwxr-xr-x. 2 root root 4096 Aug 13 2018 Documents
drwxr-xr-x. 2 root root 4096 Aug 13 2018 Downloads
-rw-r–r--. 1 root root 6577 Mar 27 2018 install-cloud-init.sh
-rw-r–r--. 1 root root 52264 Aug 13 2018 install.log
-rw-r–r--. 1 root root 10259 Aug 13 2018 install.log.syslog
-rw-r–r--. 1 root root 4122 Mar 27 2018 install-uvpvmtools.sh
-rwxrwxrwx. 1 root root 7891 Mar 27 2018 linuxguest_customize.sh
drwxr-xr-x. 2 root root 4096 Aug 13 2018 Music
-rw-r–r--. 1 root root 475422720 Sep 25 14:13 mysql-5.7.27-1.el6.x86_64.rpm-bundle.tar
-rw-r–r--. 1 7155 31415 23550204 Jun 12 14:42 mysql-community-client-5.7.27-1.el6.x86_64.rpm
-rw-r–r--. 1 7155 31415 340484 Jun 12 14:42 mysql-community-common-5.7.27-1.el6.x86_64.rpm
-rw-r–r--. 1 7155 31415 3702740 Jun 12 14:42 mysql-community-devel-5.7.27-1.el6.x86_64.rpm
-rw-r–r--. 1 7155 31415 39143304 Jun 12 14:42 mysql-community-embedded-5.7.27-1.el6.x86_64.rpm
-rw-r–r--. 1 7155 31415 136587608 Jun 12 14:42 mysql-community-embedded-devel-5.7.27-1.el6.x86_64.rpm
-rw-r–r--. 1 7155 31415 2202528 Jun 12 14:42 mysql-community-libs-5.7.27-1.el6.x86_64.rpm
-rw-r–r--. 1 7155 31415 1723712 Jun 12 14:42 mysql-community-libs-compat-5.7.27-1.el6.x86_64.rpm
-rw-r–r--. 1 7155 31415 160749952 Jun 12 14:42 mysql-community-server-5.7.27-1.el6.x86_64.rpm
-rw-r–r--. 1 7155 31415 107413748 Jun 12 14:43 mysql-community-test-5.7.27-1.el6.x86_64.rpm
-rw-r–r--. 1 root root 210877 Jan 20 2018 pdksh-5.2.14-37.el5_8.1.x86_64.rpm
按顺序依次安装
- rpm -ivh mysql-community-common-5.7.12-1.el6.x86_64.rpm
- rpm -ivh mysql-community-libs-5.7.12-1.el6.x86_64.rpm
- rpm -ivh mysql-community-devel-5.7.12-1.el6.x86_64.rpm
- rpm -ivh mysql-community-client-5.7.12-1.el6.x86_64.rpm
- rpm -ivh mysql-community-server-5.7.12-1.el6.x86_64.rpm
启动mysql
[root@oracle11g-68 ~]# service mysqld start
Initializing MySQL database: [ OK ]
Starting mysqld: [ OK ]
初次密码为空
[root@oracle11g-68 ~]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO)
为什么会出现这个错误,原因是因为MySQL5.7中的mysql.user 表中没有Password字段,所以要以安全方式登录,然后修改密码。
解决方法如下:
修改MySQL配置文件:vim /etc/my.cnf,在文件末尾加上:skip-grant-tables,保存后重启MySQL服务:service mysqld restart,然后重新登录。
修改密码,用户密码是在名为mysql的database下面:
依次执行以下指令:
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set password_expired=‘N’ where user='root;
mysql> update user set password_expired=‘N’ where user=‘root’;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update user set authentication_string=password(‘sip123456’) where user=root;
ERROR 1054 (42S22): Unknown column ‘root’ in ‘where clause’
mysql> update user set authentication_string=password(‘sip123456’) where user=‘root’;
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
编码设置:vim /etc/my.cnf,文件末尾加上编码内容default-character-set=utf8
允许远程访问MySQL:
赋予任何主机访问数据的权限
mysql>grant all privileges on . to ‘root’@’%’with grant option;
会报错:ERROR 1133 (42000): Can’t find any matching row in the user table
其实如果事先在mysql.user表中存在root用户就正常了,或,将这句末尾加上identified by ‘密码’ 也就正常了。如下面的命令行
mysql>grant all privileges on . to ‘root’@’%’identified by ‘123456’ with grant option;
更改密码策略:
mysql> set global validate_password_length=0; --更改密码长度
mysql> set global validate_password_policy=0; --更改密码策略为LOW