安裝mysql(linux 我的環境centos 7)
安裝MySQL官方的Yum Repository
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
下載rpm包
yum -y install mysql57-community-release-el7-10.noarch.rpm
安裝MySQL服務
yum -y install mysql-community-server
win版直接https://dev.mysql.com/downloads/windows/installer/下載安裝就可以
mysql 數據保存位置(win版一般需要修改保存路徑,linux默認就行)
datadir=D:/ProgramData/MySQL/MySQL Server 5.7/Data
secure-file-priv="D:/ProgramData/MySQL/MySQL Server 5.7/Uploads"
注意:Date目錄需要添加NETWORK SERVICE用戶,並添加讀寫權限
首次安裝MySQL修改密碼
修改 my.cnf(linux) 或者 my.ini(win) 在最后添加 skip-grant-tables
然后重啟mysql
systemctl restart mysqld.service
輸入mysql 就能直接進入mysql
然后輸入下面的語句就能修改密碼了
update user set authentication_string = password('密碼'), password_expired = 'N', password_last_changed = now() where user = 'root';
然后停止MySQL服務 systemctl stop mysqld.service 刪除掉my.cnf 或 my.ini剛才添加的 skip-grant-tables 這里不去掉的話,不用輸入密碼就直接能進入mysql 然后重啟服務就可以了 mysql -u root -p 輸入密碼就可以了進入mysql了
設置mysql utf8mb4(mysql 8.0 版默認utf8mb4 不需要設置)
[client] default-character-set=utf8mb4 [mysql] default-character-set=utf8mb4 [mysqld] character-set-client-handshake = FALSE character-set-server=utf8mb4 collation-server = utf8mb4_unicode_ci init_connect='SET NAMES utf8mb4'
nutz自動創表 使用@TableMeta("{mysql-charset:'utf8mb4'}")注解使創建的表使用utf8mb4編碼(這樣mysql可以存emjoi表情了)
@Table("t_table") @TableMeta("{mysql-charset:'utf8mb4'}") public class Table{ }
創建表語句
CREATE TABLE 'table' ( 'id' int NOT NULL auto_increment, 'name' varchar(50) NOT NULL, primary key('id') ) ENGINE=InnoDB CHARSET=utf8mb4 AUTO_INCREMENT=1;