1. 程式人生 > >常見問題--MySQL

常見問題--MySQL

cti blank arc 自動 server one 連接數據庫 ... jdbc

group by相關“only_full_group_by” SQL_MODE是默認開啟的,開啟後只能獲取受group by影響的字段,而對於非group by的信息需要通過any_value(name)函數獲取(mysql 5.7之後)
ibatis annotations 註解方式返回剛插入的自增長主鍵ID的值
  @Insert("insert into Product(title, image, price, detail, summary, seller) values(#{title},#{image},#{price},#{detail},#{summary},#{seller})")
  @Options(useGeneratedKeys=true
, keyProperty="id")//添加該行,product中的id將被自動添加public Integer insertProduct(Product product);

亂碼問題

tomcat造成的亂碼,在server.xml中設置:

<Connector URIEncoding="UTF-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" useBodyEncodingForURI="true" />


連接數據庫的URL中加入編碼格式,如:

jdbc.url= jdbc:mysql://127.0.0.1:3306/electronic-business?useUnicode=true&characterEncoding=UTF-8

數據庫設置:

mysql> SET character_set_client=‘gbk‘;

mysql> SET character_set_connection=‘gbk‘

mysql> SET character_set_results=‘gbk‘

mysql> SET character_set_database=‘gbk‘;

mysql> SET character_set_server=‘gbk‘

mysql> SET character_set_results=‘gbk‘

改成gbk或者utf-8都可以

常用相關命令:查看數據庫編碼格式show variables like ‘character_set_%‘;查看數據庫中的表的創建show create table tablename;設置數據庫編碼格式set names= ‘gbk‘;或者在mysql命令行下輸入 \s查看mysql的字符集的方式
blob格式引起的亂碼:blob讀出來的是ISO-8859-1編碼,你需要轉換為GBK編碼才可以Java codeString blob =...blob = new String(blob.getBytes("iso-885901"),"GBK");或者存取大文本的時候用mediumtext而不用blob
CentOS 7 通過yum安裝MySQL 5.7
1.下載YUM庫shell > wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm2.安裝YUM庫shell > yum localinstall -y mysql57-community-release-el7-7.noarch.rpm3.安裝數據庫shell > yum install -y mysql-community-server4.啟動MySQL服務shell > systemctl start mysqld.service

常見問題--MySQL