服务器之家

服务器之家 > 正文

centos7下安装mysql6初始化安装密码的方法

时间:2021-01-21 16:30     来源/作者:一夜听春雨

1.先停止数据库服务器

service  mysqld stop

2.vim /etc/my.cnf

3.配置文件添加skip-grant-tables

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[root@VM_0_8_centos ~]# vim /etc/my.cnf
 
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
 
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables      此处!!!!!!
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

4.重启数据库

 systemctl restart mysql

5.登录数据库

mysql -uroot -p

如果询问密码,直接空密码登录

6.set password for root@localhost = password('123456');括号里面的密码你自己修改。

7.mysql -uroot -p123456 登录成功

PS:下面看下Mysql初始化root密码和允许远程访问

mysql默认root用户没有密码,输入mysql –u root 进入mysql

1、初始化root密码

进入mysql数据库

?
1
mysql>update user set password=PASSWORD(‘123456') where User='root';

2、允许mysql远程访问,可以使用以下三种方式:

a、改表。

?
1
2
3
4
mysql -u root –p
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;

b、授权。

例如,你想root使用123456从任何主机连接到mysql服务器。

?
1
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

如果你想允许用户jack从ip为10.10.50.127的主机连接到mysql服务器,并使用654321作为密码

?
1
2
mysql>GRANT ALL PRIVILEGES ON *.* TO 'jack'@'10.10.50.127' IDENTIFIED BY '654321' WITH GRANT OPTION;
mysql>FLUSH RIVILEGES

c:在安装mysql的机器上运行:

?
1
2
3
4
5
6
7
8
//进入MySQL服务器
d:\mysql\bin\>mysql -h localhost -u root
//赋予任何主机访问数据的权限
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION
//使修改生效
mysql>FLUSH PRIVILEGES
//退出MySQL服务器
mysql>EXIT

总结

到此这篇关于centos7下安装mysql6初始化安装密码的方法的文章就介绍到这了,更多相关centos7下安装mysql6初始化安装密码内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://www.cnblogs.com/PiaoYu/archive/2020/06/05/13047560.html

标签:

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享 2020-04-07
返回顶部