安裝
sudo apt-get update
sudo apt-get install mysql-server
然后輸入y確認(rèn)
查看數(shù)據(jù)庫運(yùn)行狀態(tài)
systemctl status mysql.service
設(shè)置密碼
sudo mysql_secure_installation
回車之后讓你輸入密碼 這個(gè)密碼就是以后你的數(shù)據(jù)庫登錄的密碼
完成之后進(jìn)入mysql
grant all privileges on *.* to 'root'@'%' identified by 'jamkung';
flush privileges;
注意的是
>>用戶在本機(jī)root權(quán)限下還是能不用密碼就能登錄
>
>用pycharm打開數(shù)據(jù)庫,看mysql數(shù)據(jù)庫里面的user
>
>localhost root 對應(yīng)的authentication_string是空的
>
>>命令:
>>
>>`use mysql;`
>>
>>`update user set authentication_string=password("你的密碼") where user='root';`
>>
>>`update user set plugin="mysql_native_password"; `
>>
>>`flush privileges;`
>>
>>重啟mysql服務(wù)
>>
>>`systemctl restart mysql.service`
設(shè)置遠(yuǎn)程登錄
mysql5.7配置文件路徑:
/etc/mysql/mysql.conf.d/mysqld.cnf
#找到將bind-address = 127.0.0.1注銷
將字符編碼修改為能存表情的
將Mysql的編碼從utf8轉(zhuǎn)換成utf8mb4
查看當(dāng)前數(shù)據(jù)庫的編碼
show variables like '%char%';
character_set_client為客戶端編碼方式;
character_set_connection為建立連接使用的編碼瑟慈;
character_set_database數(shù)據(jù)庫的編碼薪寓;
character_set_results結(jié)果集的編碼易稠;
character_set_server數(shù)據(jù)庫服務(wù)器的編碼胶逢;
修改/etc/mysql/mysql.conf.d/mysqld.cnf
文件
[mysqld] Basic Settings下面加上
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
修改/etc/mysql/conf.d/mysql.cnf
文件
在[mysql]下方加入
default-character-set = utf8mb4
重啟數(shù)據(jù)庫再查看當(dāng)前數(shù)據(jù)庫的編碼
導(dǎo)出備份數(shù)據(jù)庫
CREATE TABLE student (
student_id VARCHAR (10) PRIMARY KEY NOT NULL,
student_name VARCHAR (20) NOT NULL,
student_sex VARCHAR (2),
student_age INTEGER (3),
dept_id VARCHAR (2),
class_id VARCHAR (8)
);
mysqldump -uroot -ppassword 數(shù)據(jù)庫名 > 導(dǎo)出到的文件夾的路徑(默認(rèn)為當(dāng)前所在的文件夾)
例如:
mysqldump -uroot -pjamkung blog > /root/backup/blog.sql
導(dǎo)入恢復(fù)數(shù)據(jù)庫
先進(jìn)Mysql創(chuàng)建一個(gè)空的數(shù)據(jù)庫名字
create database blog;
退出Mysql并在終端恢復(fù)數(shù)據(jù)
進(jìn)入到相應(yīng)sql文件的目錄
mysql -uroot -ppassword blog < blog.sql
常用命令
systemctl restart mysql.service #重啟
systemctl stop mysql.service # 停止
systemctl start mysql.service # 運(yùn)行
systemctl status mysql.service # 狀態(tài)