概述
1.ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
> 检查mysqld状态
#/etc/rc.d/init.d/mysqld status
如果是关闭的,开启
service mysqld restart
2.ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
可能是由于第一次进入没设置密码,或者密码错误。
1)关闭mysql服务
#/etc/init.d/mysqld stop
2)开启安全模式 & 后台运行
#mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
3)登录
mysql -u root mysql
方法1:
#use mysql;
#update user set password=PASSWORD('newpass') where user = 'root';
#flush privileges; // 记得要这句话,否则如果关闭先前的终端,又会出现原来的错误
#quit
#/etc/init.d/mysqld restart
#mysql -u root -p
输入新密码即可
方法2:
#mysql> insert into user (Password,User) values(PASSWORD('newpass'),'root');
#mysql> quit;
#/etc/init.d/mysqld restart
#mysql -u root -p
3.mysql创建用户以及授权
mysql>create user guest identified by '123456'; // 创建一个guest用户
mysql>grant all privileges on mytestdb.* to 'guest'@'localhost' identified by '123456'; // 授予guest在mytestdb上的权限。如果是本地的mysql,@后面用localhost;如果是远程的,采用@'%'。
mysql>flush privileges; // 刷新权限
mysql>quit
2.mysql_real_connect连接数据库的错误:
关于如何用mysql_real_connect()连接远程数据库
http://www.cnitblog.com/guopingleee/archive/2009/02/14/54548.html
(gdb) p m_pszIPAddress
$1 = "localhost", '