天天看點

mysql一建注釋_MySql常見操作

啟動MySQL服務 DOS指令視窗  net start name; net stop name;

1.關于自增字段重新賦初值的問題?

ALTER TABLE tbl AUTO_INCREMENT = 1;

2.如何實作mysql中自增長字段的功能?

create table abc(id int(10) not null auto_incremnet primary key,

name varchar(10) not null,

address varchar(200) not null,

postcode char(6) not null

);

這樣就建立了一個表,這個表的id子段是自動增長的。

你還可以在一建好的表中增加這樣的字段,操作如下:

alter table tb_name add id int(10) not null auto_increment first;

或者

alter table tb_name add id int(10) not null auto_increment;

3、如何更改mysql中使用者密碼?

a、在mysql/bin/目錄下面

./mysqladmin -u[使用者名如:root] -p[舊密碼,如果沒有密碼留白] password [新密碼]

./mysqladmin -uroot -p123456 password 456789

其中 使用者名: root 原來密碼: 123456 新密碼: 456789

b、以root使用者進入mysql

mysql> use mysql

mysql>update user set Password=password('newpassword') where User='root';

mysql>flush privileges;

注意大小寫。

4、如何遠端連接配接mysql

(1)進入mysql,建立一個新使用者xuys:

格式:grant 權限 on 資料庫名.表名 使用者@登入主機 identified by "使用者密碼";

grant select,update,insert,delete on *.* [email protected]";

identified by "xuys

檢視結果,執行:

use mysql;

select host,user,password from user;

可以看到在user表中已有剛才建立的xuys使用者。host字段表示登入的主機,其值可以用IP,也可用主機名,将host字段的值改為%就表示在任何用戶端機器上能以xuys使用者登入到mysql伺服器,建議在開發時設為%。

update user set host = '%' where user = 'xuys';

(2) mysqladmin -uroot -ppwd reload

mysqladmin -uroot -ppwd shutdown

(3)./mysqld_safe --user=root &

記住:對授權表的任何修改都需要重新reload,即執行第3步。

如果經過以上3個步驟還是無法從用戶端連接配接,請執行以下操作,

在mysql資料庫的db表中插入一條記錄:

use mysql;

insert into db values

('192.168.88.234','%','xuys','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');

update db set host = '%' where user = 'xuys';

重複執行上面的第2、3步。

上文介紹的都是在MySQL資料庫操作過程中經常會遇到的,還有很多别的問題,這裡就不一一為大家介紹了,本文比較适合初學者學習,供大家參考。