当前位置:网站主页>网站技术资料>mysql>文章内容

mysql常用命令一(登录、增加用户、密码更改)

一、连接MySQL
格式: mysql -h主机地址 -u用户名 -p用户密码
例1:连接到本机上的MYSQL。
  首先在打开 DOS 窗口,然后进入目录 %mysqlpath%\bin>,%mysqlpath%是mysql安装的主目录,再键入命令:mysql -uroot -p,回车后提示你输密码,如果刚安装好 MySQL,超级用户 root 是没有密码的,故直接回车即可进入到MySQL中了,MySQL的提示符是:mysql>.
C:\Program Files\MySQL\MySQL Server 5.0\bin>mysql -u root -p
Enter password:
Welcome to the MySQL monitor.? Commands end with ; or \g.
Your MySQL connection id is 7 to server version: 5.0.7-beta-nt
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>

例2:连接到远程主机上的 MySQL。
  假设远程主机的IP为:192.168.9.168,用户名为root,密码为abcd123。则键入以下命令: mysql -h110.110.110.110 -uroot -pabcd123 如图:
C:\Program Files\MySQL\MySQL Server 5.0\bin>mysql -h 192.168.9.168 -u root -p
Enter password:
Welcome to the MySQL monitor.? Commands end with ; or \g.
Your MySQL connection id is 9 to server version: 5.0.7-beta-nt
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>

二、增加新用户。
(注意:下面的因为是 MySQL 环境中的命令,所以命令后面都带一个分号作为结束符)
格式:grant select on 数据库.* to 用户名@登录主机 identified by "密码";
例1、增加一个用户 test1 密码为 abc123,让他可以在任何主机上登录,并对所有数据库有查询、插入、修改、删除的权限。首先用以 root 用户连入 MySQL,然后键入以下命令:
grant select, insert, update, delete on *.* to [email=test1@]test1@"%[/email]" Identified by "abc123"; 如图:
mysql> grant select, insert, update, delete on *.* to
mysql->
test1@"%"Identified by "abc123";
Query OK, 0 rows affected (0.03 sec)

但例1增加的用户是十分危险的,如某个人知道test1的密码,那么他就可以在internet上的任何一台电脑上登录你的mysql数据库并对你的数据为所欲为了,解决办法见例2。

  • 快速服务服务:网站策划 | 网站建设 | 北京网站建设 | 网站推广 | 网罗SEO
  • 联系网罗: 咨询电话:010-89630319 Mail:admin#wonlu.com Msn:刘先生 QQ:26402294
  •   2006-2008 Wonlu.com 北京网罗无限-京ICP备06036090号 网罗SEO