修改root密码:
mysqladmin -u root password "newpass"
my.cnf配置字符集:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
default-character-set = utf8
character_set_server = utf8
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
default-character-set = utf8
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysql]
default-character-set = utf8
[mysql.server]
default-character-set = utf8
1.列出MYSQL支持的所有字符集:
SHOW CHARACTER SET;
2.当前MYSQL服务器字符集设置
SHOW VARIABLES LIKE 'character_set_%';
3.当前MYSQL服务器字符集校验设置
SHOW VARIABLES LIKE 'collation_%';
4.显示某数据库字符集设置
show create database 数据库名;
5.显示某数据表字符集设置
show create table 表名;
6.修改数据库字符集
alter database 数据库名default character set 'utf8';
7.修改数据表字符集
alter table 表名default character set 'utf8';
在列d上增加一个索引,并且使列a为主键:
ALTER TABLE t2 ADD INDEX (d), ADD PRIMARY KEY (a);
删除主键,不可以指定列,而且主键的列不能为自动增长类型才能删除,否则会报错:ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key。
ALTER TABLE t2 DROP PRIMARY KEY;
增加索引:
CREATE INDEX index_name ON table_name (column_list)
CREATE UNIQUE INDEX index_name ON table_name (column_list)
删除索引:
DROP INDEX index_name ON talbe_name
ALTER TABLE table_name DROP INDEX index_name
ALTER TABLE table_name DROP PRIMARY KEY
删除列c:
ALTER TABLE t2 DROP COLUMN c;
增加一个新的AUTO_INCREMENT整数列,命名为c:
ALTER TABLE t2 ADD c INT UNSIGNED NOT NULL AUTO_INCREMENT,ADD INDEX (c);
插入记录:insert into teacher values('','glchengang','深圳一中','1976-10-10');
修改记录:update mytable set single=′y′ where name=′abccs′;
删除记录:delete from mytable where name=′abc′;
文章标题、作者应该使用var类型,提高检索效率。
文章内容使用text类型。
访问次数用INT UNSIGNED
时间日期用DATE或DATETIME
create database mqyj;
use mqyj;
create table article(
id int unsigned primary key auto_increment,
title char(128),
timeup datetime,
timeshow datetime,
count int unsigned,
content text
);
alter article add unique(title);
alter table admin modify user char(16);
alter table add xxx varchar(32);
清空数据表:
delete from table xxx;
truncate table xxx;
删除数据表:
drop table xxx;
更改列字段属性和名字:
alter table admin change oldname newname tinyint(1) not null;
导出数据:
mysqldump -h 127.0.0.1 -u root databasename tablename > bak.sql 导出表
mysqldump -h 127.0.0.1 -u root databasename > bak.sql 导出数据库
mysql -u root databasename < bak.sql 导入数据库或表(数据库必须已存在)
修复数据库:
mysql -u root
use db_name
repair table tb_name;
查看连接线程:
show processlist;
杀死线程:
kill xxx;
为某个数据库创建一个用户,这个用户只能操作这个数据库:
grant all privileges on db_name.* to [email protected] identified by 'password';
flush privileges;
不限制IP:
grant all privileges on db_name.* to username@'%' identified by 'password';
flush privileges;
注意:如果设置:
grant all privileges on *.* to [email protected] identified by 'password';
flush privileges;
相当于创建了另一个超级用户!!!