江湖博客

青春是一个充满活力的季节,即便是我们失去了天使的翅膀,只要我们还有一颗青春的心,那么我们的生活依然能够如阳光般灿烂!......
现在位置:首页 > 服务器 > Linux > linux安装mysql后root无法登录

linux安装mysql后root无法登录

very168    Linux    2016-2-11    817    0评论
问题:
[root@localhost mysql]# mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
解决方法:
方法一: 
# /etc/init.d/mysql stop 
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking & 
# mysql -u root mysql 
mysql> UPDATE user SET Password=PASSWORD(’newpassword’) where USER=’root’; 
mysql> FLUSH PRIVILEGES; 
mysql> quit 
# /etc/init.d/mysql restart 
# mysql -uroot -p 
Enter password: <输入新设的密码newpassword> 
mysql> 
方法二: 
直接使用/etc/mysql/debian.cnf文件中[client]节提供的用户名和密码: 
# mysql -udebian-sys-maint -p 
Enter password: <输入[client]节的密码> 
mysql> UPDATE user SET Password=PASSWORD(’newpassword’) where USER=’root’; 
mysql> FLUSH PRIVILEGES; 
mysql> quit 
# mysql -uroot -p 
Enter password: <输入新设的密码newpassword> 
mysql>

上面方法执行完毕后,登录mysql还需要设置密码,否则无法进行其他操作,提示需设置密码
set password=password('weixiao');

mysql安装好以后在linux下的目录
      1、数据库目录
/var/lib/mysql/
2、配置文件
/usr/share/mysql(mysql.server命令及配置文件)

3、相关命令
/usr/bin(mysqladmin mysqldump等命令)

4、启动脚本
/etc/init.d/mysql   start|stop|restart|status(启动脚本文件mysql的目录)



linux安装好服务后,开放端口命令:

/sbin/iptables -I INPUT -p tcp --dport 9090 -j ACCEPT; (区分大小写)

然后输入以下命令查看端口:

/etc/init.d/iptables status

最后还需要保存并重启防火墙

/etc/rc.d/init.d/iptables save (保存)

service iptables restart (重启)

一切ok,可以远程访问了

********************************************************

当用mysql工具远程访问的时候会报这个错:

Host  is not allowed to connect to this MySQL server

这是因为没有授权,如果你想从任何主机连接到mysql服务器的话。

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

如果你想只允许用户从固定ip的主机连接到mysql服务器的话。

grant all privileges on *.* to 'root'@'170.12.12.155' identified by 'weixiao' with grant option;

评论一下分享本文赞助博瑞

赞助博瑞X

扫码赞助博瑞
联系站长
江湖博客
挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
提交评论

清空信息
关闭评论