MySQL常用命令

2022-04-08 19:16:11 字數 2893 閱讀 4136

習慣了oracle後,第一次用mysql會不適應。在未選擇mysql的客戶端之前,都是使用命令列。

mysql -p 31306 -u uacuser1 -puacuser1

mysql -p3020 -h 130.51.23.246 -uroot -proot

mysql -p3020 -h 130.51.23.246 -uroot -p安裝了mysql後可以使用mysql命令。

-p:埠。可有空格,也可沒有。 -u:使用者名稱。可有空格,也可沒有。root是最高許可權使用者。其他使用者可以通過root建立。 -h:ip。mysql伺服器所在的主機,如果沒有預設 - 就是本機,本機的話必須是mysql使用者。 -p:密碼。必須沒有空格,緊跟-p。也可以-p後留空,提示你輸入密碼時再輸入。查詢當前使用者:

select user();create user 'uacuser1'@'localhost' identified by '123456';

create user 'uacuser1'@'aipaas03' identified by '123456';

create user 'uacuser1'@'%' identified by '123456';查詢使用者

select user,host from mysql.user order by user;刪除使用者:

delete from mysql.user where user='uacdb' and host='localhost';

delete from mysql.user where user='uacdb' and host='aipaas03';

delete from mysql.user where user='uacdb' and host='%';

flush privileges;create database uacdb;

grant all privileges on uacdb.* to uacuser1@"%" identified by "123456";

grant all privileges on uacdb.* to uacuser1@"localhost" identified by "123456";

grant all privileges on uacdb.* to uacuser1@"aipaas03" identified by "123456";

flush privileges;mysql新設定使用者或更改密碼後需用flush privileges重新整理mysql的系統許可權相關表,否則會出現拒絕訪問,還有一種方法,就是重新啟動mysql伺服器,來使新設定生效。 mysql建庫必須用root建,然後賦權使用者。查詢資料庫:

show databases;進入某個資料庫(database_name是具體的庫名):

use database_name;刪除資料庫:

drop database if exists database_name;必須進入某個庫後才能進行。

drop table if exists `auth_center`;

create table `auth_center` (

`auth_id` bigint(20) not null auto_increment,

`auth_password` varchar(48) collate utf8_bin not null,

`auth_source` varchar(16) collate utf8_bin not null default '',

`auth_param` varchar(2048) collate utf8_bin default null,

`auth_state` varchar(2) collate utf8_bin not null,

`auth_register_time` timestamp not null,

`auth_active_time` timestamp null default null,

primary key (`auth_id`)

) engine=innodb auto_increment=617 default charset=utf8 collate=utf8_bin;查詢表:

show tables;檢視表結構:

desc table_name;dml:

使用標準的dml即可。select、insert、update、delete。

show variables like '%autocommit%';mysql –v

mysql --help | grep distribstatus

select version();quit

exiterror 1044 (42000): access denied for user 『portaluser1』@』aipaas03』 to database 『protaldb』

解決:use protaldb時遇到,protaldb寫錯了;create database時遇到,必須用root使用者。

error 1045 (28000): access denied for user 『root』@』aipaas03』 (using password: yes)

解決:使用者名稱或者密碼錯了。

error 1046 (3d000): no database selected

解決:要先use 庫名。

error 2002 (hy000): can』t connect to local mysql server through socket 『/var/lib/mysql/mysql.sock』 (2)

解決:登入時遇到。需要-h mysql所在主機。或者用mysql的使用者登入主機。

error 2006 (hy000): mysql server has gone away

解決:grant all privileges 時遇到,可忽略。

2015.6.20

mysql基本常用命令 MySQL常用命令(一)

cmd提示框中的mysql基礎命令 一 命令 連線mysql伺服器 mysql h localhost u root p 展示所有資料庫 show databases 選擇資料庫 use database 展示所選資料下所有表 show tables 設定資料庫編碼 set names gbk 用s...

mysql巡檢常用命令 mysql 常用命令

客戶端連線 進入命令列,windows cmd,連線 mysql u 使用者名稱 p密碼 h 伺服器ip位址 p 伺服器端mysql埠號 d 資料庫名 注意 1 伺服器端口標誌 p一定要大些以區別於使用者 p,如果直接連線資料庫標誌 d也要大寫 2 如果要直接輸入密碼 p後面不能留有空格如 pmyp...

mysql常用命令總結 mySql常用命令總結

總結一下自己常用的mysql資料庫的常用命令 mysql u root p 進入mysql bin目錄後執行,回車後輸入密碼連線。資料庫操作 1 create database dbname 建立資料庫,資料庫名為dbname 2 create database todo default chara...