Windows
mysql版本地址 https://dev.mysql.com/downloads/mysql/
1官册、解壓到自定義文件夾姊途,如 D:\mysql-8.0.22-winx64
并在當(dāng)前路徑下創(chuàng)建my.ini文件
[mysql]
# 設(shè)置mysql客戶端默認(rèn)字符集
default-character-set=utf8
[mysqld]
#設(shè)置3306端口
port = 3306
# 設(shè)置mysql的安裝目錄
basedir=D:\mysql-8.0.22-winx64 # 記住要更改這個(gè)路徑
# 設(shè)置mysql數(shù)據(jù)庫的數(shù)據(jù)的存放目錄
datadir=D:\mysql-8.0.22-winx64\data # 記住要更改這個(gè)路徑
# 允許最大連接數(shù)
max_connections=200
# 服務(wù)端使用的字符集默認(rèn)為UTF8
character-set-server=utf8
# 創(chuàng)建新表時(shí)將使用的默認(rèn)存儲(chǔ)引擎
default-storage-engine=INNODB
2、新建數(shù)據(jù)目錄(其實(shí)可以不用創(chuàng)建术浪,當(dāng)執(zhí)行 mysqld --install后會(huì)自動(dòng)創(chuàng)建) D:\mysql-8.0.22-winx64\data
3、設(shè)置環(huán)境變量 3.1臼予、新建環(huán)境變量: 變量名 MYSQL_HOME 變量路徑? D:\mysql-8.0.22-winx64? ? 3.2侣颂、在PATH添加環(huán)境變量路徑 D:\mysql-8.0.22-winx64\bin
4、使用管理員運(yùn)行cmd
mysqld --install
mysqld --initialize --console
記錄下root的臨時(shí)密碼:root@localhost:*8)q6jIuwV<t
5迹辐、啟動(dòng)數(shù)據(jù)庫
net start mysql
6蝶防、登錄數(shù)據(jù)庫(擁有root權(quán)限)
mysql -uroot -proot
7、修改初始密碼
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password';
刷新權(quán)限:
flush privileges;
show variables like '%char%'; ? 顯示編碼參數(shù),確認(rèn)是UTF-8
8明吩、創(chuàng)建新的用戶
create user new_user identified by 'new_user';
create user walden identified by 'walden';
9间学、賦予該用戶指定數(shù)據(jù)庫的操作權(quán)限(% 表示可遠(yuǎn)程登陸,localhost表示只能本機(jī)登錄)
grant 權(quán)限 on 數(shù)據(jù)庫.* to 用戶名@登錄主機(jī);
grant all on walden* to 'walden'@'%';
10印荔、修改密碼規(guī)則:(否則無法遠(yuǎn)程登陸)
ALTER USER 'new_user'@'%' IDENTIFIED BY 'new_user' PASSWORD EXPIRE NEVER;
ALTER USER 'new_user'@'%' IDENTIFIED WITH mysql_native_password BY 'new_user';
Linux
搜索?
apt-cache search mysql
卸載?
apt-get purge mysql*?
apt-get purge mariadb*
or centos
rpm -qa|grep mariadb
#mariadb-libs-5.5.60-1.el7_5.x86_64
rpm -e --nodeps mariadb? #tab補(bǔ)齊
下載mysql安裝包
地址 https://dev.mysql.com/downloads/mysql/
包 https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
解壓
tar xvJf **.tar.xz mkdir /usr/local/mysql mv mysql-8.0.13-linux-glibc2.12-x86_64/ /usr/local/mysql cd /usr/local/mysql
配置文件etc下的my.cnf
rm /etc/my.cnf
vim /etc/my.cnf
? ? [mysql]
? ? # 設(shè)置mysql客戶端默認(rèn)字符集
? ? default-character-set=utf8mb4
? ? [mysqld]
? ? skip-name-resolve
? ? #設(shè)置3306端口
? ? port = 3306
? ? # 設(shè)置mysql的安裝目錄
? ? basedir=/usr/local/mysql
? ? # 設(shè)置mysql數(shù)據(jù)庫的數(shù)據(jù)的存放目錄
? ? datadir=/usr/local/mysql/data
? ? # 允許最大連接數(shù)
? ? max_connections=200
? ? # 服務(wù)端使用的字符集默認(rèn)為8比特編碼的latin1字符集
? ? character-set-server=utf8mb4
? ? # 創(chuàng)建新表時(shí)將使用的默認(rèn)存儲(chǔ)引擎,innodb支持事物
? ? default-storage-engine=INNODB
? ? lower_case_table_names=1
? ? max_allowed_packet=16M
創(chuàng)建mysql用戶和組
cat /etc/group | grep mysql?
?cat /etc/passwd | grep mysql
#沒有就u添加
groupadd mysql
?useradd -g mysql mysql?
?passwd mysql
#當(dāng)前所屬賦給mysql
mkdir -R /usr/local/mysql/data
#在mysql中添加data文件夾
chown -R mysql /home/mysql/
chgrp -R mysql /home/mysql/
#chown -R mysql:mysql /home/mysql/ 效果一樣
安裝?
cd /usr/local/mysql && bin/mysqld --initialize --user=mysql? --datadir=/usr/local/mysql/data/
記住密碼低葫,比如 root@localhost: ;I/w8T4sr%.l
創(chuàng)建軟連接
ln -s /usr/local/mysql/support-files/mysql.server /usr/bin/mysqld
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
啟動(dòng)mysql
mysqld start
修改默認(rèn)密碼
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mysql';
刷新權(quán)限
flush privileges;