1. 時間與時間戳的轉換mysql
1.1 時間戳轉時間sql
FROM_UNIXTIME(add_time, '%Y-%m-%d')數據庫
1.2 時間轉時間戳bash
UNIX_TIMESTAMP('2015-04-29') ui
2. 修改mysql用戶名或者密碼spa
2.1 修改用戶名code
mysql -u root -p Enter password:*** mysql> use 你的數據庫; 選擇數據庫 Database changed mysql> update user set user="新的用戶名" where user="原來的用戶名"; mysql> flush privileges; 刷新權限 mysql> exit
2.2 修改密碼orm
mysql -u root -p Enter password:*** mysql>use 你的數據庫; Database changed mysql> UPDATE user SET password=PASSWORD("新密碼") WHERE user='你的用戶名'; mysql> FLUSH PRIVILEGES; mysql> quit;
3. Navicat導入數據報錯-1153-Gotapacketbiggerthan'maxallowedpacket'bytesblog
緣由: mysql默認執行sql文件的大小最大值爲16M,若是超過這個數值就會報錯索引
解決: 修改mysql的配置文件, 如my.ini 設置 max_allowed_packet=500M(具體大小看狀況而定)
4. mysql 判斷字段是否存在, 不存在則添加該字段
DROP PROCEDURE IF EXISTS schema_change; DELIMITER // CREATE PROCEDURE schema_change() BEGIN DECLARE CurrentDatabase VARCHAR(100); SELECT DATABASE() INTO CurrentDatabase; IF NOT EXISTS (SELECT * FROM information_schema.columns WHERE table_schema=CurrentDatabase AND table_name = 'activity_log' AND column_name = 'desc') THEN ALTER TABLE activity_log ADD COLUMN `desc` TINYINT NOT NULL DEFAULT 0 COMMENT '666'; END IF; END// DELIMITER ; CALL schema_change();
5. 判斷索引是否存在,不存在建立
DROP PROCEDURE IF EXISTS schema_change; DELIMITER // CREATE PROCEDURE schema_change() BEGIN DECLARE CurrentDatabase VARCHAR(100); SELECT DATABASE() INTO CurrentDatabase; IF NOT EXISTS (SELECT * FROM information_schema.statistics WHERE table_schema=CurrentDatabase AND table_name = 'activity_log' AND index_name = 'log_index') THEN ALTER TABLE `activity_log` ADD INDEX index_name ( `log_index` ); END IF; END// DELIMITER ; CALL schema_change();