1.下载mysql rpm包
在该网站选择相应的包 http://dev.mysql.com/downloads/mysql/5.0.html
这里选择:MySQL-server-5.6.17-1.sles11.x86_64.rpm 和 MySQL-client-5.6.17-1.sles11.x86_64.rpm
安装这两个包,执行 rpm -ivh MySQL-server-5.6.17-1.sles11.x86_64.rpm
rpm -ivh MySQL-client-5.6.17-1.sles11.x86_64.rpm
2.启动mysql
/etc/init.d/mysql start
3.连接mysql
- [root@localhost bin]# ./mysql -uroot -p12345
- ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
遇到上面情况怎么办,请按如下步骤操作:
1、停止mysql服务
- [root@localhost bin]# chkconfig --list | grep -i mysql
- mysql 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
- [root@localhost bin]# service mysql stop
- Shutting down MySQL [确定]
2、用mysqld_safe重启服务
- [root@localhost bin]# ./mysqld_safe --user=root --skip-grant-tables --skip-networking &
- [1] 3818
- [root@localhost bin]# 111105 07:30:32 mysqld_safe Logging to '/usr/local/mysql/var/localhost.localdomain.err'.
- 111105 07:30:32 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/var
- ./mysql -uroot mysql
- Welcome to the MySQL monitor. Commands end with ; or g.
- Your MySQL connection id is 1
- Server version: 5.1.48-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.
3、重设密码
- mysql> update user set password=password('12345') where user='root' ;
- Query OK, 3 rows affected (0.05 sec)
- Rows matched: 3 Changed: 3 Warnings: 0
- mysql> flush privileges;
- Query OK, 0 rows affected (0.00 sec)
- mysql> quit
- Bye
4、重启服务
- [root@localhost bin]#service mysql stop
- [root@localhost bin]# service mysql start
5、再次连接数据库
- [root@localhost bin]# ./mysql -uroot -p12345
- Welcome to the MySQL monitor. Commands end with ; or g.
- Your MySQL connection id is 1
- Server version: 5.1.48-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用户,使之可以远程连接
格式:grant select on 数据库.* to 用户名@登录主机 identified by "密码"
例1、增加一个用户user_1密码为123,让他可以在任何主机上登录,并对所有数据库有查询、插入、修改、删除的权限。首先用以root用户连入MySQL,然后键入以下命令:
mysql> grant select,insert,update,delete on *.* to user_1@"%" Identified by "123";
例1增加的用户是十分危险的,如果知道了user_1的密码,那么他就可以在网上的任何一台电脑上登录你的MySQL数据库并对你的数据为所欲为了,解决办法见例2。
例2、增加一个用户user_2密码为123,让此用户只可以在localhost上登录,并可以对数据库aaa进行查询、插入、修改、删除的 操作(localhost指本地主机,即MySQL数据库所在的那台主机),这样用户即使用知道user_2的密码,他也无法从网上直接访问数据库,只能 通过MYSQL主机来操作aaa库。
mysql>grant select,insert,update,delete on aaa.* to user_2@localhost identified by "123";
用新增的用户如果登录不了MySQL,在登录时用如下命令:
mysql -u user_1 -p -h 192.168.113.50 (-h后跟的是要登录主机的ip地址)