MYSQL登录错误:mysqladmin: connect to server at ‘localhost’ failed
一、mysql登录错误
mysqladmin: connect to server at ‘localhost’ failed error: ‘Access denied for user
‘root’@’localhost’ (using password: YES)’
解决办法:破解mysql密码
service mysqld stop
#>mysqld_safe --skip-grant-tables &
输入 mysql -uroot -p 回车进入
>use mysql;
> update user set password=PASSWORD("123456")where user="root";
更改密码为 newpassord
> flush privileges; 更新权限
> quit 退出
service mysqld restart
mysql -uroot -p新密码进入
二,忘记本地root的登录密码
解决过程:
1、编辑/etc/my.cnf
在[mysqld] 配置部分添加一行
skip-grant-tables
2、保存后重启mysql
[root@localhost etc]# service mysqld restart
Shutting down MySQL. [ OK ]
Starting MySQL. [ OK ]
3
3、登录数据库重新设置root密码
[root@localhost ~]# mysql -uroot -p root123
Enter password:
直接回车进入
mysql 配置文件目录:/etc/my.cnf
root 密码为空的时候配置文件中下面这句:
skip-grant-tables
GRANT ALL PRIVILEGES ON *.* TO IDENTIFIED BY '123' WITH GRANT OPTION;
执行这句时候错误:
ERROR 1290 (HY000): The MySQL server is running with the –skip-grant-tables option so it cannot execute this statement
mysql> GRANT ALL PRIVILEGES ON *.* TO IDENTIFIED BY '123' WITH GRANT OPTION;
ERROR 1290 (HY000): The MySQL server is running with the –skip-grant-tables option so it cannot execute this statement
这个时候我们只需要 flush privileges一下,在添加用户就OK了,
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO IDENTIFIED BY '123' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
这
个时候我们成功搞定了,再登录就可以了。
如果报错如下信息:
Error: Cannot retrieve repository metadata (repomd.xml) for repository: InstallMedia. Please verify its path and try again
You could try using –skip-broken to work around the problem
You could try running: rpm -Va –nofiles –nodigest
我们只要到/etc/yum.repo.s下面把packetxxxx.repo和redhat.repo两个文件删除掉,再启动就可以了
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.47-log Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)
执行下列语句
mysql> update user set password=password("123456") where user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
4、删除/etc/my.cnf文件中添加的“skip-grant-tables”行,重启mysql;
用新设的密码就能正常登录了;
三
直接mysql回车就好了,不要加-u -p参数,就会使用默认的root@localhost登录。
如果你想改密码,要先选择数据库
use mysql
然后操作
四
第一种方法:可能是硬盘满了,清理下垃圾文件。
第二种:
查看下数据库运行状态
/etc/init.d/mysql status
提示
ERROR! MySQL is running but PID file could not be found
先打印MYSQL进程
ps aux | grep mysql
然后KILL进程
kill -9 pid1 pid2 …
再启动MYSQL
/etc/init.d/mysql start
再检查mysql运行状态
/etc/init.d/mysql status
提示成功
第三种:是修改过my.cnf配置出错引起 执行命令:vi /etc/my.cnf 修改内容:
[mysqld]
port= 3306
socket= /var/lib/mysql/mysql.sock
在令,OK
五、通过rpm方式安装的mysql,没有一个具体的文件夹,所以存在许多无法找到配置文件、启动文件等等的问题,下面这个图片可以帮助解决这个问题:
而且,之前会遇到的sock文件无法找的问题:该文件是在启动mysql的时候自动生成的,所以如果遇到问题,文件就会消失,所以不用刻意去找这个文件,然后每次遇到问题后,不要尝试去重新启动或者连接,先要做的操作是ps -ef | grep mysql 来kill -9 掉僵尸进程不然,你后面的操作是无法正常执行的。
六、能够正常登陆mysql以后,却报了错:
然后,正常解决问题。
问题六
hive> show tables;
FAILED: Error in metadata: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask
用下面的命令,重新启动hive
[b]./hive -hiveconf hive.root.logger=DEBUG,console [/b][b]进行[/b][b]debug[/b]
问题七
Caused by: org.datanucleus.store.rdbms.datasource.DatastoreDriverNotFoundException: The specified datastore driver (“com.mysql.jdbc.Driver”) was not found in the CLASSPATH. Please check your CLASSPATH specification, and the name of the driver.
解决方法:
这说明没有添或者添加错了mysql-connector-java-5.1.29.jar 包添加jar包即可
问题八
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user ‘hadoopuser’@’localhost’ to database ‘hive_metastore’
解决方法:
这是因为mysql数据库用户hadoopuser 的权限不足,赋予权限
grant all on hive_metastore.* to 'hadoopuser'@'localhost' ;
问题九
mysql: unknown variable
‘sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABL 问题
出现: unknown variable
‘sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABL,最后在/etc/my.cnf 中,把sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABL 删掉或者注释掉,发现问题解决了。
问题十
MySQL: mysql is not running but lock exists 的解决方法
rm -rf /var/lock/subsys/mysql
然后启动mysql,一切正常了,这里的可能原因就是可能和log文件有关,于是将log文件给移除了,再重启MySQL终于OK了。
问题十一
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
1、先查看 /etc/rc.d/init.d/mysqld status 看看m y s q l 是否已经启动.
另外看看是不是权限问题.
2、确定你的mysql.sock是不是在那个位置,
mysql -u 你的mysql用户名 -p -S /var/lib/mysql/mysql.sock
3、试试:service mysqld start
4、如果是权限问题,则先改变权限
#chown -R mysql:mysql /var/lib/mysql
[root@localhost ~]# /etc/init.d/mysqld start
启动 MySQL: [ 确定 ]
[root@localhost ~]# mysql -uroot -p
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
原因是,/var/lib/mysql 的访问权限问题。
shell> chown -R mysql:mysql /var/lib/mysql
接着启动服务器
shell> /etc/init.d/mysql start
服务器正常启动后察看 /var/lib/mysql 自动生成mysql.sock文件。
但是我的问题仍然没有得到解决。
问题终于解决:
方法:修改/etc/my.conf:
[mysqld]
datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock
[mysql.server]
user=mysql
basedir=/usr/local/mysql
If there is not currently a section called [client], add one at the bottom of the file and copy the socket= line under the [mysqld] section such as:
[client]
socket=/var/lib/mysql/mysql.sock
发现依旧如此,运行
/etc/init.d/mysql start报错:Starting MySQLCouldn’t find MySQL manager or server
是mysqld服务没启,运行/usr/local/mysql/bin/mysqld_safe &