Centos6.5安装Mysql5.6.10

时间:2022-09-22 12:26:18

1. 先卸载掉老版本的mysql(linux严格区分大小写,查找的时候加上-i参数,和mysql相关的全部要卸)

[root@liuchao ~]# rpm -qa | grep -i mysql
MySQL-devel-5.6.10-1.rhel5.x86_64
MySQL-server-5.6.10-1.rhel5.x86_64
MySQL-client-5.6.10-1.rhel5.x86_64

卸载(如果卸载不了,在命令后面加上--nodeps 强制卸载 eg: rpm -e mysql-libs-5.1.71-1.el6.x86_64 --nodeps)

2. 需要的安装文件

先下载下面三个文件

MySQL-devel-5.6.10-1.rhel5.x86_64
MySQL-server-5.6.10-1.rhel5.x86_64
MySQL-client-5.6.10-1.rhel5.x86_64

3. 安装

[root@liuchao software]# rpm -ivh MySQL-devel-5.6.10-1.rhel5.x86_64.rpm
Preparing... ########################################### [100%]
1:MySQL-devel ########################################### [100%]

[root@liuchao software]# rpm -ivh MySQL-client-5.6.10-1.rhel5.x86_64.rpm
Preparing... ########################################### [100%]
1:MySQL-client ########################################### [100%]

[root@liuchao software]# rpm -ivh MySQL-server-5.6.10-1.rhel5.x86_64.rpm
Preparing... ########################################### [100%]
1:MySQL-server ########################################### [100%]

4. 启动

[root@liuchao software] service mysql start

5. Mysql的默认密码

先查看.mysql_secret文件,最后面的串就是root的初始登陆密码(A1wCMNXo)
[root@liuchao ~]# cat /root/.mysql_secret
# The random password set for the root user at Fri Jun 27 03:22:55 2014 (local time): A1wCMNXo

6. 登陆

[root@liuchao ~]# mysql -uroot -p
Enter password: 这里输入上面的密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.10

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>
mysql> show databases;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql>

7. 提示修改密码才可以登陆

mysql> show databases;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
修改密码
mysql> set password = password('123456');
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye

8. 修改完成之后再登陆

[root@liuchao ~]# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.10 MySQL Community Server (GPL)

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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.01 sec)

mysql>

9. Navicat 8 for MySQL 连接(报错,这是因为需要远程登陆授权)

1103 - Host '192.168.6.46' is not allowed to connection to this MySQL server

 

mysql -u root -p123456
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>flush privileges;
然后退出重启一下mysql就行了

10. 授权的时候报错

在执行update user set host = '%' where user = 'root';报错
mysql> update user set host = '%' where user = 'root';
ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'
那就直接执行下面的命令
mysql>flush privileges;
然后退出重启mysql就行了

11. 重启mysql

[root@liuchao local]# service mysql restart
Shutting down MySQL....[ OK ]
Starting MySQL..[ OK ]

 12. 安装完mysql发现

A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.

You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.

Also, the account for the anonymous user has been removed.

In addition, you can run:

/usr/bin/mysql_secure_installation

which will also give you the option of removing the test database.
This is strongly recommended for production servers.

See the manual for more instructions.

Please report any problems with the /usr/bin/mysqlbug script!

The latest information about MySQL is available on the web at

http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

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

MYSQL的默认配置文件在/usr/my.cnf并没有在/etc/my.cnf文件中