標籤:mysql忘記密碼 基本sql語句
登入mysql
mysql -p 輸入密碼登入
1、查看mysql版本
mysql > select version();或者是你登入進mysql 的時候會有一大段輸出資訊,那裡也包含版本資訊
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/6C/6D/wKioL1VJjYGBo9gHAAKnIvdNebM995.jpg" title="QQ20150506113646.png" alt="wKioL1VJjYGBo9gHAAKnIvdNebM995.jpg" />
2、查看當前登入到mysql的使用者
mysql > select user();
3、查看當前資料庫中有哪些使用者
mysql > select user from mysql.user;
4、查看當前資料庫中有哪些使用者、host和密碼
mysql > select user,host,password from mysql.user;
5、查看123456加密後的字串是什麼
mysql > select password(‘123456‘);
6、修改root密碼 這裡設定為123456
mysql > use mysql;
mysql > update user set password=password(‘123456‘) where user=‘root‘;
7、如果忘記root密碼,重啟mysql加參數--skip-grant-tables 可以免密碼登入
# service mysqld stop 停掉mysql服務
# /usr/bin/mysqld_save --skip-grant-tables & 以命令列參數啟動mysql
# mysql 進入資料庫執行6的操作修改密碼
8、建立字元集是utf8的資料庫
mysql > create database ceshi character set utf8;
9、建立使用者管理資料庫
mysql > grant all privileges on ceshi.* to ‘ceshi‘@‘%‘ identified by ‘123456‘;
10、建立表
mysql > create table test (id int(11),name varchar(16));
11、向表中插入資料
mysql > insert into test valuses (1,‘xiaohong‘);
批量插入
mysql > insert into test valuses (2,‘xiaoli‘),(3,‘hanmei‘);
12、添加、修改、刪除欄位格式
mysql > ALTER TABLE table_name ADD field_name field_type; 添加欄位
mysql > ALTER TABLE table_name CHANGE old_field_name new_field_name field_type;修改原欄位名稱及類型
mysql > ALTER TABLE table_name DROP field_name;刪除欄位
mysql>ALTER TABLE `user_movement_log` CHANGE `GatewayId` `GatewayId` int not null default 0 AFTER RegionID;調整列的順序
13、在id欄位前添加一個age欄位 tinyint(2)
mysql > alter table test add age tinyint(2)not Null after id;
14、刪除age欄位
mysql > alter table test drop column age;
15、查看某個資料庫大小
怎樣用命令查看Mysql資料庫大小
1、進去指定schema 資料庫(存放了其他的資料庫的資訊)
mysql > use information_schema
2、查詢所有資料的大小
mysql > select concat(round(sum(DATA_LENGTH/1024/1024),2),‘MB‘) as data from TABLES
3、查看指定資料庫的大小
比如說 資料庫apoyl
mysql > select concat(round(sum(DATA_LENGTH/1024/1024),2),‘MB‘) as data from TABLES where table_schema=‘apoyl‘;
4、查看指定資料庫的表的大小
比如說 資料庫apoyl 中apoyl_test表
mysql > select concat(round(sum(DATA_LENGTH/1024/1024),2),‘MB‘) as data from TABLES where table_schema=‘apoyl‘ and table_name=‘apoyl_test‘;
15、將test表中的order_id欄位改成decimal(30,0)這個類型
mysql > alter table test modify order_id decimal(30,0) unsigned NULL;
16、查看哪些線程正在運行
mysql > show processlist;
17、
mysql > show engines;看你的mysql現在已提供什麼儲存引擎:
mysql > show variables like ‘%storage_engine%‘;看你的mysql當前預設的儲存引擎:
mysql > show variables like ‘%slow%‘; 查看慢查詢日誌路徑及是否開啟
本文出自 “煥然一新” 部落格,請務必保留此出處http://4374568.blog.51cto.com/4364568/1642439
mysql基本命令