mysql在windows上如何使用

2021-07-15 09:00:02 字數 2459 閱讀 2645

1.進入mysql資料庫控制台, 

mysql -u root -p ,或者mysql

庫操作2.顯示所有的資料庫 

命令:show databases; (注意:最後有個s) 

mysql> show databases; 

3.建立資料庫 

命令:create database 《資料庫名》 ;

4.刪除資料庫 

命令:drop database 《資料庫名》 ;

5.連線資料庫 

命令: use 《資料庫名》 

例如:如果test資料庫存在,嘗試訪問它: 

mysql> use test;

6.檢視當前使用的資料庫 

mysql> select database(); 

7.當前資料庫包含的表資訊: 

mysql> show tables; (注意:最後有個s)

表操作8.建表

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)); 

9.獲取表結構 

命令: desc 表名,或者show columns from 表名 

mysql>describe myclass 

mysql> desc myclass; 

mysql> show columns from myclass; 

10.刪除表 

命令:drop table 《表名》 

例如:刪除表名為 myclass 的表 

mysql> drop table myclass; 

11.插入資料 

命令:insert into 《表名》 [( 《欄位名1>[,..《欄位名n > ])] values ( 值1 )[, ( 值n )] 

例如,往表 myclass中插入二條記錄, 這二條記錄表示:編號為1的名為tom的成績為96.45, 編號為2 的名為joan 的成績為82.99,編

號為3 的名為wang 的成績為96.5. 

mysql> insert into myclass values(1,'tom',96.45),(2,'joan',82.99), (2,'wang', 96.59); 

12.查詢表中的資料 

1)、查詢所有行 

命令: select 《欄位1,欄位2,...> from < 表名 > where < 表示式 > 

例如:檢視表 myclass 中所有資料 

mysql> select * from myclass; 

2)、查詢前幾行資料 

例如:檢視表 myclass 中前2行資料 

mysql> select * from myclass order by id limit 0,2;

13. 刪除表中資料 

14. 修改表中資料

15.在表中增加字段: 

命令:alter table 表名 add欄位 型別 其他; 

例如:在表myclass中新增了乙個欄位passtest,型別為int(4),預設值為0 

mysql> alter table myclass add passtest int(4) default '0'

16.更改表名: 

命令:rename table 原表名 to 新錶名; 

例如:在表myclass名字更改為youclass 

mysql> rename table myclass to youclass; 

17.更改root密碼

use mysql;

show tables;

update user set authentication_string=password('liujianjy') where user='root';

exit

mysql -u root -p  就可以輸密碼進入了

ps:檢視列:desc 表名;

修改表名:alter table t_book rename to bbb;

新增列:alter table 表名 add column 列名 varchar(30);

刪除列:alter table 表名 drop column 列名;

修改列名mysql: alter table bbb change nnnnn hh int;

修改列名sqlserver:exec sp_rename't_student.name','nn','column';

修改列名oracle:lter table bbb rename column nnnnn to hh int;

修改列屬性:alter table t_book modify name varchar(22);

在Windows上安裝MySQL

選擇mysql installer 這裡要輸入資料庫的密碼 這個名稱是資料庫的名字。最後安裝完成。前面步驟完成後安裝好mysql,為mysql配置環境變數。mysql預設安裝在c program files下。1 新建mysql home變數,並配置 c program files mysql my...

在windows上安裝mysql

新建my.ini檔案 client port 3306 mysqld 設定3306埠 port 3306 設定mysql的安裝目錄,注意斜槓,需要兩個 basedir d mysql 8.0.23 winx64 設定mysql資料庫的資料的存放目錄 datadir d mysql 8.0.23 wi...

在windows上安裝mysql

新建my.ini檔案 client port 3306 mysqld 設定3306埠 port 3306 設定mysql的安裝目錄,注意斜槓,需要兩個 basedir d mysql 8.0.23 winx64 設定mysql資料庫的資料的存放目錄 datadir d mysql 8.0.23 wi...