分类: Mysql/postgreSQL
2010-02-01 17:56:25
增加一个管理员帐户:grant all on *.* to user@localhost identified by "password"; 查询时间:select now(); 查询当前用户:select user(); 查询数据库版本:select version(); 查询当前使用的数据库:select database(); 列出数据库:show databases; 选择数据库:use databaseName; 列出表格:show tables; 增加一个管理员帐户:grant all on *.* to user@localhost identified by "password"; 或授权一个新用户: grant select,insert,update,delete on *.* to user@localhost Identified by "123"; 如果是远程用户: localhost改为% 或者"%" 更改表的字符集: mysql> alter table users character set GBK; 这时向表中插入中文然后有错误。 mysql> insert into users values(88,'中文'); ERROR 1366 (HY000): Incorrect string value: '\xD6\xD0\xCE\xC4' for column 'usern ame' at row 1 mysql> insert into users values(88,'中文'); ERROR 1366 (HY000): Incorrect string value: '\xD6\xD0\xCE\xC4' for column 'usern ame' at row 1 还要更改users表的username的字符集。 mysql> alter table users modify username char(20) character set gbk; ERROR 1366 (HY000): Incorrect string value: '\xC0\xEE\xCB\xC4' for column 'usern ame' at row 1 mysql> alter table users modify username char(20) character set gbk; ERROR 1366 (HY000): Incorrect string value: '\xC0\xEE\xCB\xC4' for column 'usern ame' at row 1 因为表中已经有数据,所以更改username字符集的操作没有成*** 清空users表中的数据 mysql> truncate table users; Query OK, 3 rows affected (0.01 sec) 从新更改user表中username的字符集 mysql> alter table users modify username char(20) character set gbk; Query OK, 0 rows affected (0.06 sec) Records: 0 Duplicates: 0 Warnings: 0 这时再插入中文字符,插入成***。 mysql> insert into users values(88,'中文'); Query OK, 1 row affected (0.01 sec) mysql> select * from users; +--------+----------+ | userid | username | +--------+----------+ | 88 | 中文 | +--------+----------+ 1 row in set (0.00 sec) mysql> |