mysql在linux上出现Access denied for user 'root'@'localhost' (using password: NO)解决方案


在linux上安装mysql遇到的

mysql版本(mysql-5.7.13-linux-glibc2.5-i686.tar.gz)

安装时参考的文章:http://blog.163.com/ji_1006/blog/static/106123412015104103948782/


安装完成后启动:sudo /etc/init.d/mysqld start

打开mysql: mysql -uroot -p

则提示:

https://img-blog.csdn.net/20160727221323161?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center


解决了好久,大家都说

1../mysqld_safe --user=root --skip-grant-tables --skip-networking &

2.update user set password=password('12345') where user='root' ; 

可是新版的mysql里没有password这个字段了惊恐

最终解决问题如下:

1.查看当前密码:sudo cat /root/.mysql_secret

2.登陆:mysql -uroot -p 提示密码时输入上条命令cat出来的密码,成功登陆mysql

3.通过mysql命令修改密码:alter user 'root'@'localhost' identified by ’登陆进来的密码’;

4.update mysql.user set authentication_string=password('您的密码') where user='root' and Host='localhost';

5.写入:flush privileges;

6.退出quit


编码问题

创建数据库:
mysql> create database dbname if not exists dbname DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci设置utf8编码

为确保 create database dbname 命令创建的数据库编码集为utf8, 我们可对mysql的配置文件进行修改windows下的mysql配置文件为my.ini, my.ini存在于mysql的安装目录下linux下的mysql配置文件为my.cnf, mysql.cnf存在于mysql的安装目录下或/etc/下在my.cnf或my.ini下找到[mysqld], 在其下方添加一行:
character_set_server=utf8
然后保存退出, 并重启mysql服务即可。
查看字符编码:
mysql> show variables like '%character%';

mysql> show variables like 'character_set_%';

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值