当前位置: 移动技术网 > IT编程>数据库>Mysql > centos7下安装mysql6初始化安装密码的方法

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

2020年06月14日  | 移动技术网IT编程  | 我要评论

1.先停止数据库服务器

service  mysqld stop

2.vim /etc/my.cnf

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

[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 = password('123456');括号里面的密码你自己修改。

7.mysql -uroot -p123456 登录成功

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

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

1、初始化root密码

进入mysql数据库

mysql>update user set password=password(‘123456') where user='root';

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

a、改表。

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服务器。

mysql>grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;

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

mysql>grant all privileges on *.* to 'jack'@'10.10.50.127' identified by '654321' with grant option;
mysql>flush rivileges

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

//进入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初始化安装密码内容请搜索移动技术网以前的文章或继续浏览下面的相关文章希望大家以后多多支持移动技术网!

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网