prompt \u@ceshi \r:\m:s-> ###臨時改變命令提示符mysql
若是想永久生效放入my.conf裏面的 [mysql]下面 prompt \u@ceshi \r:\m:s->sql
mysql登陸數據庫
# mysql -h 127.0.0.1 -u mysql -P 3000 #遠程鏈接 IP + 端口bash
mysql -h localhost -u root -S /data/ops/app/mysql-5.6.23/3307/3307.sock app
MySQL修改root密碼的多種方法 在 Navicat for MySQL 下面直接執行 SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass'); 就能夠 方法1: 用SET PASSWORD命令 mysql -u root mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass'); 方法2:用mysqladmin mysqladmin -u root password "newpass" 若是root已經設置過密碼,採用以下方法 mysqladmin -u root password oldpass "newpass" 方法3: 用UPDATE直接編輯user表 mysql -u root mysql> use mysql; mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root'; mysql> FLUSH PRIVILEGES; 在丟失root密碼的時候,能夠這樣 mysqld_safe --skip-grant-tables& mysql -u root mysql mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root'; mysql> FLUSH PRIVILEGES;
##生產環境
./mysqld_safe --defaults-file=/data/ops/app/mysql-5.6.23/etc/3308.cnf --skip-grant-tables --user=mysql&
mysql> update mysql.user set password=password('123456') where user='root';
mysql> flush privileges;
mysqladmin -h127.0.0.1 -uroot -p shutdown ###輸入密碼123456
mysql -h127.0.0.1 -uroot -P3003 -p #輸入密碼登陸成功123456
sql---平常操做ide
mysql> select user,host,password from mysql.user order by user; ##查詢並排序 mysql> delete from mysql.user where user=' '; ##刪除用戶 mysql> create database test; 建立數據庫 mysql> show create database test\G #查看建立數據庫,默認建立字符集latin1 mysql> create database test_gbk DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci; ###建立指定的字符集數據庫 mysql> show create dabases test_gbk\G ##查看建立的數據庫發現字符集變成gbk mysql> create database test_utf8 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; ###建立utf8數據庫 mysql> show create dabases test_utf8\G ##查看建立的數據庫字符集變成utf8 ##提示 字符集的不一致是數據庫中午亂碼的罪魁禍首,有關字符集的看後面 ##提示 若是變異的時候指定了字符集 之後建立數據庫就不須要指定了 企業裏: 1根據開發的程序肯定字符集(建議用utf8) 2.編譯的時候指定字符集 3.編譯的時候沒有指定字符集或者指定了和程序不一樣的字符集,若是解決? ###指定字符集建立數據庫便可。 顯示數據庫 show databases; select database(); 刪除數據庫 mysql> drop database test; 切換數據庫 use test_utf8; 查看版本 select version(); 查看當前用戶 select user(); 查看當前時間 select now(); 建立用戶 mysql> create user 'haha'@'localhost' identified by '123'; 刪除用戶 mysql> drop user 'haha'@'localhost'; 建立並受權 grant all privileges on test.* to oldboy@'localhost' identified by 'oldboy123'; 查看用戶權限 mysql> show grants for oldboy@localhost; 只受權 grant all ON test.* to 'haha'@'localhost'; 遠程受權 mysql> create user test@'10.0.0.%' identified by 'test'; 回收權限 mysql> show grants for oldboy@localhost; +---------------------------------------------------------------------------------------------------------------+ | Grants for oldboy@localhost | +---------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'oldboy'@'localhost' IDENTIFIED BY PASSWORD '*FE28814B4A8B3309DAC6ED7D3237ADED6DA1E515' | | GRANT ALL PRIVILEGES ON `test`.* TO 'oldboy'@'localhost' | +---------------------------------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec) mysql> revoke insert on test.* from 'oldboy'@'localhost'; Query OK, 0 rows affected (0.00 sec) mysql> show grants for oldboy@localhost; 企業環境儘可能最小化權限,只給增刪改查,把建立刪除收回。 建立表 mysql> create table tutorials_tbl( tutorial_id INT NOT NULL AUTO_INCREMENT, tutorial_title VARCHAR(100) NOT NULL, tutorial_author VARCHAR(40) NOT NULL, submission_date DATE, PRIMARY KEY ( tutorial_id ) ); 查看錶結構 mysql> desc tutorials_tbl; mysql> show create table tutorials_tbl;