五种常用的MySQL命令行


  本文标签:MySQL命令行

  MySQL命令行对我们使用MySQL数据库起到了很大的帮助作用,下面就为您介绍五种常用的MySQL命令行用法,供您参考学习  。

  1.[不同端口登录]

  通过开始菜单-> 程序-> MySQL-> MySQL Command Line Client
通过输入密码Enter password:******进行登录 该MySQL服务端口已定

  或者

  通过运行命令->C:\Program Files\MySQL\MySQL Server 5.2\bin>
然后利用mysql进行登录
C:\Program Files\MySQL\MySQL Server 5.2\bin>mysql -uroot -h127.0.0.1 -P3307 -p
Enter password:******
亦可选择登录远程MySQL

  2.[执行SQL文件]

  创建测试数据库及数据表
mysql> source c:/test/test.sql;

  test.sql文件内容:
create database IF NOT EXISTS testdb;

  use testdb;

  create table testtable
(testName varchar(10));

  3.[创建用户]

  mysql> create user testuser identified by testpass;

  4.[赋予权限]

  mysql> grant all privileges on testdb.* to testuser@% identified by testpass;

  5.[修改root密码]

  如果已登录
1)use mysql 
2)update user set password=password(你的密码) where user=root;
3)flush privileges;

  如果没登录,你想进数据库而没有密码

  先关掉服务
然后以safe模式进入
mysqld_safe --skip-grant-tables &
这个窗口不要关,这样进数据库就不用密码,进去后做 “如果已登录”的步骤  。