gtxyzz

MySQL命令行 不同端口登录 执行SQL文件 创建用户 赋予权限 修改root密码

gtxyzz 系统安装 2023-02-27 705浏览 0

0.安装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 &
  这个窗口不要关,这样进数据库就不用密码,进去后 做 “如果已登录”的 步骤

继续浏览有关 数据库技术文章/教程 的文章
发表评论