赞
踩
安装环境:CentOS6 64位 ,安装MySQL5.6
在MySQL官网中下载YUM源rpm安装包:https://dev.mysql.com/downloads/repo/yum/
wget http://dev.mysql.com/get/mysql57-community-release-el6-7.noarch.rpm
安装mysql源
yum localinstall mysql57-community-release-el6-7.noarch.rpm
检查mysql源是否安装成功
yum repolist enabled | grep "mysql.*-community.*"
可以修改vim /etc/yum.repos.d/mysql-community.repo
源,改变默认安装的mysql版本。比如要安装5.6版本,将5.7源的enabled=1改成enabled=0。然后再将5.6源的enabled=0改成enabled=1即可。
改完之后的效果如下所示:
yum install mysql-community-server
- 1 service mysqld status --查看有没有打开服务
- 2 service mysqld start --打开服务
- 3 service mysqld stop --停止服务
- 4 service mysqld restart --重启服务
1、查看mysql是否自启动,这里是在linux中执行的并且设置开启自启动命令
# chkconfig --list | grep mysqld
mysqld 0:off 1:off 2:off 3:on 4:on 5:on 6:off
2、设置开机启动
# chkconfig mysqld on
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
由于mysql刚刚安装完的时候,mysql的root用户的密码默认是空的,所以我们需要及时用mysql的root用户登录(第一次回车键,不用输入密码),并修改密码
- [root@localhost ~]# mysql -u root
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 2
- Server version: 5.6.41 MySQL Community Server (GPL)
-
- Copyright (c) 2000, 2018, 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> 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 authentication_string=password('321') where user = 'root';
- Query OK, 4 rows affected (0.02 sec)
- Rows matched: 4 Changed: 4 Warnings: 0
-
- [root@localhost ~]# flush privileges;
- Query OK, 0 rows affected (0.02 sec)
-
-
- 接着执行:
-
- SELECT * from mysql.user\G;
- 去找到root用户的authentication_string这项,并把它的值记下来。
-
- MySQL会给密码进行加密,你想要设置的密码进行加密后的值就等于此时authentication_string这项的值
-
- 所以接下来把Password这项的值也设置成此时authentication_string项的值就ok了;我设置的密码是321 ,其对应的密文是 *7297C3E22DEB91303FC493303A8158AD4231F486
-
- 执行下面两条sql语句:
-
- update mysql.user set password = '*7297C3E22DEB91303FC493303A8158AD4231F486' where user = 'root';
- flush privileges;
可以跳过密码登录:
#vim /etc/my.cnf(注:windows下修改的是my.ini)
在文档内搜索mysqld定位到[mysqld]文本段:
/mysqld(在vim编辑状态下直接输入该命令可搜索文本内容)
在[mysqld]后面任意一行添加“skip-grant-tables”用来跳过密码验证的过程,如下图所示:
保存文档并退出:
#:wq
2.接下来我们需要重启MySQL:
/etc/init.d/mysql restart(有些用户可能需要使用/etc/init.d/mysqld restart)
3.重启之后输入#mysql即可进入mysql。
grant all on *.* to root@'%' identified by 'password' with grant option;
flush privileges;
参考:https://blog.csdn.net/hua1011161696/article/details/80666025、https://www.jianshu.com/p/3cf566658ad6
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。