標籤:不相容 ast varchar .net 訪問 custom 字串轉換 rename use
命令建立
mysql
資料庫
:
先啟動mysql資料庫,串連資料庫:
mysql -uroot -p123456 (文法:mysql -u登入名稱 -p密碼)
建立表:
create database spring_data; (文法:create database 資料庫名稱)
使用建立的資料庫:
use spring_data;
查看是否存在表:
show tables;
#查看錶中的列
SHOW COLUMNS FROM auth_user;
建立表格:
create table student( id int not null auto_increment, name varchar(20) not null, age int not null, primary key(id));
查看錶結構:
DESCRIBE auth_user;
文法:describe 表名 是 show columns from 表名 的一種捷徑。
二、修改mysql資料庫密碼
方法一:
使用phpmyadmin,直接修改Mysql庫的user 表。或者使用Navicat for Mysql 直接修改串連屬性。
方法二:使用mysqladmin
#cmd,運行DOS,cd到mysql的bin檔案夾,然後執行如下:
D:\Mysql\bin>mysqladmin -u root -p password newPwd
#Enter password:(在此輸入原密碼)
#newPwd指的是新密碼
然後開啟mysql 直接輸入新密碼即可
格式:mysqladmin -u使用者名稱 -p舊密碼 password 新密碼。
訪問資料庫,使用use語句
建立資料庫
mysql> CREATE DATABASE 庫名;
mysql> USE 庫名;
mysql> CREATE TABLE 表名 (欄位名 VARCHAR(20), 欄位名 CHAR(1));
刪除資料庫:
mysql> DROP DATABASE 庫名;
刪除資料表:
mysql> DROP TABLE 表名;
將表中記錄清空:
mysql> DELETE FROM 表名;
建立表(複雜形式):
#建立customer表:
create table customers( id int not null auto_increment, name char(20) not null, address char(50) null, city char(50) null, age int not null, love char(50) not null default ‘No habbit‘, primary key(id))engine=InnoDB;
SELECT last_insert_id(); 這個函數可以獲得返回最後一個auto_increment值.
#預設值:default ‘No habbit‘,
#引擎類型,多為engine = InnoDB,如果省略了engine=語句,則使用預設的引擎(MyISAM)
更改表結構:
#增加一列:文法:alter table tablename add colummname type [null];
alter table pet add des char(100) null;
#刪除:文法:alter table tablename drop column colummname;
alter table pet drop column des;
重新命名表:
文法:rename table tablename1 to tablename2;
rename table pet to animals;
添加id欄位
則可操作如下:
#添加id欄位,包括主鍵
alter table pet add id int not null primary key auto_increment first;
設定索引:
若要設定外鍵,在參照表(referencing table,即Pc表) 和被參照表 (referenced table,即parts表) 中,相對應的兩個欄位必須都設定索引(index)。
對Parts表:
ALTER TABLE parts ADD INDEX idx_model (model);
這句話的意思是,為 parts 表增加一個索引,索引建立在 model 欄位上,給這個索引起個名字叫idx_model。
MyBatis SQL語句 符號不相容 大於符號 小於符號 (XML逸出字元)
當我們需要通過xml格式處理sql語句時,經常會用到< ,<=,>,>=等符號,但是很容易引起xml格式的錯誤,這樣會導致後台將xml字串轉換為xml文檔時報錯,從而導致程式錯誤。這樣的問題在MyBatis中或者自訂的xml處理sql的程式中經常需要我們來處理。其實很簡單,我們只需作如下替換即可避免上述的錯誤:
原符號 |
< |
<= |
> |
>= |
& |
‘ |
" |
替換符號 |
< |
<= |
> |
>= |
& |
‘ |
" |
mysql基礎知識之-資料庫的建立、查看等常用操作