mysql命令整理 mysql常用命令整理

2021-10-17 21:17:21 字數 1819 閱讀 1457

整理下常用命令,方便記憶,沒事可拿出來瞅瞅,;

1、連線mysql資料庫:

#mysql -h 1.1.1.1 -uroot -p zabbix

2、mysql改密碼

mysqladmin命令格式: mysqladmin -u 使用者名稱 -p 舊密碼 password 新密碼(password函式)

2)忘記root密碼

重新啟動mysqld

3、mysql建新使用者並授權

grant select,insert,update,delete on *.* to test1@」%」 identified by 「abc」;

4、mysql增刪改查

建庫:建立資料庫並分配使用者:

create database 資料庫名;

grant select,insert,update,delete,create,drop,alter on 資料庫名.* to 資料庫名@localhost identified by '密碼';

set password for '資料庫名'@'localhost' = old_password('密碼');

建表:mysql> create table myclass(> id int(4) not null primary key auto_increment,> name char(20) not null,> *** int(4) not null default '0',> degree double(16,2));

如果存在則刪庫:mysql> drop database if exists drop_database;

刪表: mysql>drop table ;

刪表記錄:mysql> delete from myclass where id=1;

刪索引:mysql> alter table 表名 drop index 索引名;

刪字段:mysql> alter table 表名 drop 欄位名;

表中插入記錄:mysql> insert into table values(1,'tom',96),(2,'joan',99), (2,'wang', 59);

修改表中資料:mysql> update table set name='mary' where id=1;

加索引:mysql> alter table 表名 add index 索引名 (欄位名1[,欄位名2 …]);

加主鍵索引:mysql> alter table 表名 add primary key (欄位名);

加唯一限制條件索引:mysql> alter table 表名 add unique 索引名 (欄位名);

新增新字段:alter table 表名 add 欄位名 int not null default 0 after `regionid` (可指定字段位置)

修改欄位名及欄位型別:mysql> alter table table_name change old_field_name new_field_name field_type;

重新命名表:alter table t1 rename t2;/ rename table 原表名 to 新錶名;

查表結構:desc 表名;/ mysql> show columns from myclass;

查表中資料:select from < 表名 > where < 表示式 >;

5、資料庫備份mysqldump

備份表結構:mysqldump -u user_name -p -d �add-drop-table database_name > outfile_name.sql-d 沒有資料 �add-drop-table 在每個create語句之前增加乙個drop table

mysql檢視mylog命令 mysql常用命令

連線mysql 1.登入mysql資料庫 mysql u使用者名稱 p密碼 示例 2.登入遠端主機的mysql mysql h遠端主機ip位址 u使用者名稱 p密碼 示例 注 建立使用者命令格式為 create user hehe 192.168.93.151 3.退出mysql命令 exit 修改...

MySQL 命令整理

1 mysql服務的啟動和停止 net stop mysql net start mysql 2 登陸mysql command line 因為預設是以root使用者登入到mysql資料庫,如果需要以其它使用者登入,可以到mysql安裝目錄 bin下執行 mysql u 使用者名稱 p 資料庫 3 ...

mysql命令整理 MySQL常用命令整理

建立使用者 create user 使用者名稱 identified by 密碼 重新整理系統許可權表 flush privileges 為此使用者授予資料庫增刪改查的許可權 grant select,update,delete,insert on 資料庫名.to 使用者名稱 使用者管理 mysql...