mysql root 无法在 linux 本地登陆

来源:互联网 发布:软件腰带剑多少钱 编辑:程序博客网 时间:2024/06/04 18:01
mysql 授权

1.让用户在所有ip都可以登录
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
flush privileges;

2.让用户在指定ip可以登录
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
flush privileges;


3.如果用户无法从本地登陆,这个时候就执行如下
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost.localdomain' IDENTIFIED BY '123456' WITH GRANT OPTION;
flush privileges;

4.如果用户依然无法从本地登陆,这个时候就执行如下
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '123456' WITH GRANT OPTION;
flush privileges;

5.如果还无法本地登陆,并且报错是无法找到 mysql.sock 文件,需要修改一下 my.cnf 文件
添加如下内容:
[mysql.server]
user=mysql
basedir=/opt/tools/mysql

[client]
#这个是 sock 文件位置
socket=/opt/tools/mysql/mysql.sock

完整的 my.cnf 文件配置

[mysqld]
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
datadir=/opt/tools/mysql
socket=/opt/tools/mysql/mysql.sock
user=mysql
default-character-set=utf8
log-slow-queries = /opt/logs/mysql/slowquery.log
long_query_time = 1  #单位是秒
log-queries-not-using-indexes

# Disabling symbolic-links is recommended to prevent assorted security risks
set-variable=max_connections=1000
max_allowed_packet=20M
innodb_buffer_pool_size=1G
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysql.server]
user=mysql
basedir=/opt/tools/mysql

[client]
socket=/opt/tools/mysql/mysql.sock


[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid


0 0
原创粉丝点击