linux下sql语句,15、sql语句集,Linux 下PHP查询mysql

mysql密码,默认没有

如果想更改的话, mysqladmin  -uroot   password  root123

登录   : [root@localhost root]#   mysql    -uroot    -proot123

1、创建book数据库

mysql>   create   database   book;

Query OK, 1 row affected (0.08 sec)

2、授权给 lili 用户

mysql>  grant   all   on   book.*   to   lili@localhost   identified   by   "lili123";

Query OK, 0 rows affected (0.06 sec)

mysql> exit

Bye

3、lili登录

创建lili用户

[root@localhost html]#   mysql   -u   lili    -p

Enter password:       (这里输密码)

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 5 to server version: 3.23.54

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

4、创建book表,添加数据

mysql> use  book;    (先确定要操作的数据库)

Database changed

5、创建book表

mysql> create   table   book(

-> id   int   not   null,

-> name   char(20)   not   null,

-> primary   key(id)

-> );

Query OK, 0 rows affected (0.08 sec)

6、添加数据

mysql>  insert   into   book   values

-> (1,"语文"),

-> (2,"数学"),

-> (3,"英语");

Query OK, 3 rows affected (0.00 sec)

Records: 3  Duplicates: 0  Warnings: 0

(注意:上面操作也可以用sql语句集来执行:   (好处是,去别的机子也可以执行sql语句集 就行,不用从头打过)

[root@localhost html]#  cat  >  lili.sql

use   book;

create   table   book(

id   int   not   null,

name   char(20)   not  null,

primary   key(id)

);

insert   into  book  values

(1,"语文",),

(2,"数学"),

(3,"英语");

[root@localhost html]# vi  root.sql

create   database   book;

grant   all   on   book.*   to   lili@localhost   identified   by   "lili123" ;

[root@localhost html]# mysql   -u   root   -p  

Enter password:

[root@localhost html]# mysql   -u   lili   -p  

Enter password:

)

7、查询表

mysql> select   *   from   book;

+----+--------+

| id | name   |

+----+--------+

|  1 | 语文 |

|  2 | 数学 |

|  3 | 英语 |

+----+--------+

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值