一、Windows版:zip方式
1、下载zip包
https://dev.mysql.com/downloads/mysql/
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.20-winx64.zip
解压到 D:\Program Files\mysql-5.7.20-winx64
2、在bin同级目录,新建my.ini文件
D:\Program Files\mysql-5.7.20-winx64\my.ini
[mysql]
default-character-set=utf8
[mysqld]
port=3306
basedir="D:/Program Files/mysql-5.7.20-winx64/"
datadir="D:/Program Files/mysql-5.7.20-winx64/data"
character-set-server=utf8
default-storage-engine=INNODB
max_connections=100
3、以管理员身份运行cmd,在bin目录执行:
..\bin> .\mysqld --initialize-insecure --user=mysql
..\bin> .\mysqld install
4、连接mysql
..\bin> .\mysql -uroot -p
5、修改密码
..\bin> mysqladmin -u root password root
或
mysql> set password=password('root')
6、启动停止
cmd> net stop mysql
cmd> net start mysql
二、Linux版(centos7.2):yum方式
1、安装yum源
mysql官网yum源
http://dev.mysql.com/downloads/repo/yum/
下载yum源
shell> wget -c https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
安装yum源
shell> yum localinstall mysql57-community-release-el7-11.noarch.rpm
检查yum源
shell> yum repolist enabled | grep "mysql.*-community.*"
修改mysql yum源
shell> vim /etc/yum.repos.d/mysql-community.repo
8.0版本
shell> wget -c https://repo.mysql.com/mysql80-community-release-el7-2.noarch.rpm
shell> yum localinstall mysql80-community-release-el7-2.noarch.rpm
2、安装mysql
shell> yum install mysql-community-server
3、启动mysql
shell> systemctl start mysqld
查看启动状态
shell> systemctl status mysqld
4、设置开机启动
shell> systemctl enable mysqld
shell> systemctl daemon-reload
5、修改密码
查看默认密码
shell> grep 'temporary password' /var/log/mysqld.log
连接mysql
shell> mysql -uroot -p
修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass2!';
或
mysql> set password for 'root'@'localhost'=password('MyNewPass2!');
6、添加远程登录用户
mysql> GRANT ALL PRIVILEGES ON *.* TO 'remoteuser'@'%' IDENTIFIED BY 'RemotePass2!' WITH GRANT OPTION;
7、配置默认编码
shell> vi /etc/my.cnf
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
8、重启mysql
shell> service mysqld restart
9、默认配置文件路径
配置文件:/etc/my.cnf
日志文件:/var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid