CentOS 6.7 下RPM方式安装MySQL 5.6

1. 下载Linux对应的RPM包,如:CentOS6.7_64对应的RPM包,如下:

[root@mysql ~]# ll
总用量 113808
-rw-------. 1 root root    1434 12月 13 18:47 anaconda-ks.cfg
-rw-r--r--. 1 root root    42556 12月 13 18:47 install.log
-rw-r--r--. 1 root root    10033 12月 13 18:45 install.log.syslog
-rw-r--r--. 1 root root 23135399 12月 13 18:56 MySQL-client-5.6.25-1.linux_glibc2.5.x86_64.rpm
-rw-r--r--. 1 root root  4586217 12月 13 18:56 MySQL-devel-5.6.25-1.linux_glibc2.5.x86_64.rpm
-rw-r--r--. 1 root root 88715219 12月 13 18:56 MySQL-server-5.6.25-1.linux_glibc2.5.x86_64.rpm

2. 检查MySQL及相关RPM包,是否安装,如果有安装,则移除(rpm –e 名称)
[root@mysql ~]# rpm -qa | grep -i mysql
mysql-libs-5.1.73-5.el6_6.x86_64
[root@mysql ~]# rpm -ev mysql-libs-5.1.73-5.el6_6.x86_64 --nodeps

3. 安装MySQL
[root@mysql ~]# rpm -ivh MySQL-server-5.6.25-1.linux_glibc2.5.x86_64.rpm
Preparing...                ########################################### [100%]
  1:MySQL-server          ########################################### [100%]
warning: user mysql does not exist - using root
warning: group mysql does not exist - using root
Support MySQL by buying support/licenses at
New default config file was created as /usr/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings
[root@mysql ~]# rpm -ivh MySQL-devel-5.6.25-1.linux_glibc2.5.x86_64.rpm
Preparing...                ########################################### [100%]
  1:MySQL-devel            ########################################### [100%]
[root@mysql ~]# rpm -ivh MySQL-client-5.6.25-1.linux_glibc2.5.x86_64.rpm
Preparing...                ########################################### [100%]
  1:MySQL-client          ########################################### [100%]

4. 初始化MySQL及设置密码
[root@mysql ~]# /usr/bin/mysql_install_db            -- mysql_install_db脚本来生成帐户和相应权限许可表
WARNING: The host 'mysql' could not be looked up with /usr/bin/resolveip.
This probably means that your libc libraries are not 100 % compatible
。。省略输出。。
WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server
[root@mysql ~]# service mysql start
Starting MySQL. SUCCESS!
[root@mysql ~]# cat /root/.mysql_secret    --查看root账号密码
# The random password set for the root user at Tue Dec 13 18:59:06 2016 (local time): 7MhtyX3aZEl9OUf8
[root@mysql ~]# mysql -uroot -p
Enter password:              --(此处复制粘贴 7MhtyX3aZEl9OUf8)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.2
Copyright (c) 2000, 2015, 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> SET PASSWORD = PASSWORD('123456');  --设置密码为123456

5. 允许远程登陆
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> select host,user,password from user;
+-----------+------+-------------------------------------------+
| host      | user | password                                  |
+-----------+------+-------------------------------------------+
| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| mysql    | root | *6D95CDA252C85345E8BC1C4168E962D3949C30F9 |
| 127.0.0.1 | root | *6D95CDA252C85345E8BC1C4168E962D3949C30F9 |
| ::1      | root | *6D95CDA252C85345E8BC1C4168E962D3949C30F9 |
+-----------+------+-------------------------------------------+
4 rows in set (0.00 sec)
mysql> update user set password=password('123456') where user='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 4  Changed: 3  Warnings: 0
mysql> update user set host='%' where user='root' and host='localhost';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit

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

转载注明出处:https://www.heiqu.com/11e487b5933ea0addfbb807fc2aa16b1.html