centos7.2安装mysql5.6.38

来源:互联网 发布:零一数据分析 编辑:程序博客网 时间:2024/06/10 18:20
在网上找了一下资料,发现都不是很适合,所以自己结合各个版本的方法总结了一下。
一、下载mysql
下载地址:https://dev.mysql.com/downloads/
11
选择要下载的版本
22

33

44

55
注意:centos内核基于Red Hat,所以下载的时候需要下载Red Hat版本
二、安装mysql
1)查看系统是否已安装mysql
[root@jdu4e00u53f7 mysql]# rpm -qa | grep -i mysql
MySQL-client-5.6.38-1.el7.x86_64
MySQL-server-5.6.38-1.el7.x86_64
MySQL-devel-5.6.38-1.el7.x86_64
2)卸载
[root@jdu4e00u53f7 mysql]# rpm -e MySQL-client-5.6.38-1.el7.x86_64
[root@jdu4e00u53f7 mysql]# rpm -e MySQL-server-5.6.38-1.el7.x86_64
[root@jdu4e00u53f7 mysql]# rpm -e MySQL-devel-5.6.38-1.el7.x86_64
3)删除服务
[root@jdu4e00u53f7 mysql]# chkconfig --list | grep -i mysql
[root@jdu4e00u53f7 mysql]# chkconfig --del mysql
4)删除mysql分散的文件夹
查找
[root@jdu4e00u53f7 /]# find / -name *mysql*
删除
rm -rf /use/lib/mysql...
5) 上传,解压
解压 tar -xvf MySQL-5.6.38-1.el7.x86_64.rpm-bundle.tar (注意,是-xvf不是-zxvf)
-rw-r--r-- 1 root root 243793920 Nov 17 09:57 MySQL-5.6.38-1.el7.x86_64.rpm-bundle.tar
-rw-r--r-- 1 7155 31415 20322752 Sep 14 19:00 MySQL-client-5.6.38-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 3535660 Sep 14 19:00 MySQL-devel-5.6.38-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 93055580 Sep 14 19:01 MySQL-embedded-5.6.38-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 62422764 Sep 14 19:01 MySQL-server-5.6.38-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 2105180 Sep 14 19:01 MySQL-shared-5.6.38-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 2299632 Sep 14 19:01 MySQL-shared-compat-5.6.38-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 60042116 Sep 14 19:01 MySQL-test-5.6.38-1.el7.x86_64.rpm
6)卸载MariaDB
[root@jdu4e00u53f7 mysql] rpm -qa | grep mariadb
mariadb-libs-5.5.41-2.el7_0.x86_64
[root@jdu4e00u53f7 mysql] rpm -e --nodeps mariadb-libs-5.5.41-2.el7_0.x86_64
7)安装mysql
按顺序安装
rpm -ivh MySQL-client-5.6.38-1.el7.x86_64.rpm
rpm -ivh MySQL-devel-5.6.38-1.el7.x86_64.rpm
rpm -ivh MySQL-server-5.6.38-1.el7.x86_64.rpm
8)启动mysql
[root@jdu4e00u53f7 mysql]# service mysql status
SUCCESS! MySQL running (17886)
[root@jdu4e00u53f7 mysql]# netstat -ano | grep 3306
tcp6 0 0 :::3306 :::* LISTEN off (0.00/0/0)
三、修改密码
[root@jdu4e00u53f7 mysql]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
连接mysql的时候发现没有初始密码,不能连接
1)停止服务
[root@jdu4e00u53f7 ~]# service mysql stop
Shutting down MySQL.. SUCCESS!
2)绕过密码登录
[root@jdu4e00u53f7 ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[1] 18369
[root@jdu4e00u53f7 ~]# 171117 10:54:38 mysqld_safe Logging to '/var/lib/mysql/jdu4e00u53f7.err'.
171117 10:54:38 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

[root@jdu4e00u53f7 ~]# 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.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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>
3)登录成功之后修改密码
a)切换数据库
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

b)查询用户
mysql> select Host,User,Password from user;
+--------------+------+-------------------------------------------+
| Host | User | Password |
+--------------+------+-------------------------------------------+
| localhost | root | *FAAFFE644E901CFAFBEC7562415C5FAEC243B8B2 |
| XXXXX | root | *FAAFFE644E901CFAFBEC7562415C5FAEC243B8B2 |
| 127.0.0.1 | root | *FAAFFE644E901CFAFBEC7562415C5FAEC243B8B2 |
| ::1 | root | *FAAFFE644E901CFAFBEC7562415C5FAEC243B8B2 |
+--------------+------+-------------------------------------------+
4 rows in set (0.00 sec)
c)修改密码
mysql> UPDATE user SET password=password("root") WHERE user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0

mysql>
d)退出、重新登录
mysql> quit;
Bye
[root@jdu4e00u53f7 ~]# mysql -u root -proot
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 4
Server version: 5.6.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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开机启动

[root@jdu4e00u53f7 mysql]# chkconfig --list mysql

Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.

If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.

mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@jdu4e00u53f7 mysql]#

如果不是开机自启动,使用开启MySQL服务自动开启命令:
chkconfig mysqld on
chkconfig mysql on


mysql集合重要目录
/var/lib/mysql 数据库文件
/usr/share/mysql 命令及配置文件
/usr/bin mysqladmin、mysqldump等命令

五、设置数据库允许其它计算机访问
a)打开数据库下边的mysql库
b)执行sql
INSERT INTO `user` (`Host`, `User`, `Password`, `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv`, `Grant_priv`, `References_priv`, `Index_priv`, `Alter_priv`, `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv`, `Create_view_priv`, `Show_view_priv`, `Create_routine_priv`, `Alter_routine_priv`, `Create_user_priv`, `Event_priv`, `Trigger_priv`, `Create_tablespace_priv`, `ssl_type`, `ssl_cipher`, `x509_issuer`, `x509_subject`, `max_questions`, `max_updates`, `max_connections`, `max_user_connections`, `plugin`, `authentication_string`, `password_expired`) VALUES ('%', 'root', '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', '', '', '', '', '0', '0', '0', '0', 'mysql_native_password', '', 'N');
c)刷新权限
flush privileges;




原创粉丝点击