mysql安装之后初始化root密码

1.首先通过find / - name my.cnf找到这个文件。在[mysqld]下面加上skip-grant-tables,此时你登录mysql就不需要密码了。

[mysqld]
default_password_lifetime=0
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
skip-grant-tables
[mysqld_safe]
log-error=/usr/local/mysql/logs/mysqld.log
pid-file=/usr/local/mysql/pids/mysqld.pid

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[client]
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock

[mysql]
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

2.改完之后,你需要重启一下mysql。命令:service mysql restart

3.启动之后,登录mysql。命令 mysql -uroot -p        

  密码随便输入就行,进入之后输入 :use mysql,选择数据库。

4. 然后执行 update mysql.user set authentication_string = password('root') where user='root';

5.然后把my.cnf改回来重启一下mysql就好了。

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值