- 增加/刪除用戶
create user 'username'@'localhost' identified by 'password';
其中l(wèi)ocalhost是限制登錄方法储玫,localhost是本地登錄胰耗,%是不限制登錄方式
drop user 'username'@'localhost';刪除用戶 - 授權(quán)
grant all privileges on . to 'username'@'localhost' identified by 'password';
其中第一個是數(shù)據(jù)庫缤言,第二個是數(shù)據(jù)表灰伟,all pribileges可以換為select,update,... - 修改Root密碼
use mysql;
update user set authentication_string=password('xfgeg') where user='root';
新版本mysql中mysql.user表已經(jīng)沒有password字段,改為authentication_string - 操作完更新信息表
flush privileges; - 基本操作
create database XXX;
use XXX;
create table yyy (
id INT NOT NULL AUTO_INCREMENT,
experimenter VARCHAR(30) not null,
t7 DOUBLE,
NOTE VARCHAR(100),
exp_date DATETIME NOT NULL default now(),
PRIMARY KEY(id)
);
delete from yyy;
truncate table yyy; //刪除所有記錄植康,id從1開始
其中now()是mysql中的一個函數(shù)可以默認插入當前時間效扫。 - mysql> create table a like users; //復制表結(jié)構(gòu)
- DROP TABLE table_name ; //刪除表
- select count(*) from table_names; //查詢個數(shù)
————————————————————————————更新————————————————————
忘記root 密碼
參考:http://blog.51cto.com/lxsym/477027
1.修改MySQL的登錄設置:
vi /etc/my.cnf
在[mysqld]的段中加上一句:skip-grant-tables 保存并且退出vi。
2.重新啟動mysqld
/etc/init.d/mysqld restart ( service mysqld restart )
3.登錄并修改MySQL的root密碼(見上)
4.將MySQL的登錄設置修改回來
vi /etc/my.cnf
將剛才在[mysqld]的段中加上的skip-grant-tables刪除席覆,保存并且退出vi史辙。
5.重新啟動mysqld
/etc/init.d/mysqld restart ( service mysqld restart )
6.恢復服務器的正常工作狀態(tài)
連接報錯 Character set 'utf8mb4' is not a compiled character set and is not specified in the '/usr/share/mysql/charsets/Index.xml' file
參考http://www.aichengxu.com/mysql/11824.htm
把配置文件/usr/share/mysql/charsets/Index.xml中的utf8編碼改為utf8mb4即可,<charset name="utf8">改為<charset name="utf8mb4">
查詢用戶
SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;
重置從1遞增
alter table table_name auto_increment=1;