安装双版本Mysql
注意:多版本就不要添加环境变量,非多版本的话吧 bin
目录添加环境变量 PATH
中,即可从任何目录下通过命令行启动mysql
一、安装mysql
1.1 编写配置文件
查看端口是否被占用:netstat -ano | findstr 端口号
mysql8
[mysqld]
# 这里设置3307端口
port=3307 #需要确保端口未被占用
# 设置mysql的安装目录
basedir=D:\Program Files (x86)\phpStudy_64\phpstudy_pro\Extensions\MySQL8.0.30 #需要更改为自己mysql的根目录
# 设置mysql数据库的数据的存放目录
datadir=D:\Program Files (x86)\phpStudy_64\phpstudy_pro\Extensions\MySQL8.0.30\data #mysql根目录+data
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3307
default-character-set=utf8
mysql5
[mysql]
default-character-set=utf8
[mysqld]
port=3306
basedir=D:/Program Files (x86)/phpStudy_64/phpstudy_pro/Extensions/MySQL5.7.26/ #需要更改为自己mysql的根目录
datadir=D:/Program Files (x86)/phpStudy_64/phpstudy_pro/Extensions/MySQL5.7.26/data/ #mysql根目录+data
character-set-server=utf8
default-storage-engine=MyIsam
max_connections=100
collation-server=utf8_unicode_ci
init_connect='SET NAMES utf8'
innodb_buffer_pool_size=64M
innodb_flush_log_at_trx_commit=1
innodb_lock_wait_timeout=120
innodb_log_buffer_size=4M
innodb_log_file_size=256M
interactive_timeout=120
join_buffer_size=2M
key_buffer_size=32M
log_error_verbosity=1
max_allowed_packet=16M
max_heap_table_size=64M
myisam_max_sort_file_size=64G
myisam_sort_buffer_size=32M
read_buffer_size=512kb
read_rnd_buffer_size=4M
server_id=1
skip-external-locking=on
sort_buffer_size=256kb
table_open_cache=256
thread_cache_size=16
tmp_table_size=64M
wait_timeout=120
skip-grant-tables
[client]
port=3306
default-character-set=utf8
1.2 安装mysql服务并进行初始化
一下命令都需要管理模式下运行,以管理员模式打开cmd,切换到对应版本的mysqlbin目录,进行以下操作
mysql8
D:\Program Files (x86)\phpStudy_64\phpstudy_pro\Extensions\MySQL8.0.30\bin>mysqld --install mysql80
D:\Program Files (x86)\phpStudy_64\phpstudy_pro\Extensions\MySQL8.0.30\bin>mysqld --initialize-insecure
mysql5
#切换目录
C:\Windows\system32>d:
D:\>cd D:\Program Files (x86)\phpStudy_64\phpstudy_pro\Extensions\MySQL5.7.26\bin
D:\Program Files (x86)\phpStudy_64\phpstudy_pro\Extensions\MySQL5.7.26\bin>
#安装
D:\Program Files (x86)\phpStudy_64\phpstudy_pro\Extensions\MySQL5.7.26\bin>mysqld --install mysql57
D:\Program Files (x86)\phpStudy_64\phpstudy_pro\Extensions\MySQL5.7.26\bin>mysqld --initialize-insecure
1.3 启动服务
mysql8
# 启动mysql服务
net start mysql80
# 停止mysql服务
net stop mysql80
mysql5
# 启动mysql服务
net start mysql57
# 停止mysql服务
net stop mysql57
如果启动不成功,需要去修改一下注册表中mysql服务的路径地址
win+R,输入regedit
1.4 修改密码
在对应的版本的bin目录下,输入一下命令即可
mysql8
D:\Program Files (x86)\phpStudy_64\phpstudy_pro\Extensions\MySQL8.0.30\bin>mysql -uroot -p -P3307
mysql>alter user 'root'@'localhost' identified with mysql_native_password by '123456';
# 刷新权限
flush privileges;
mysql5
D:\Program Files (x86)\phpStudy_64\phpstudy_pro\Extensions\MySQL5.7.26\bin>mysql -uroot -p -P3306
mysql>update mysql.user set authentication_string=password("123456") where user='root' and Host='localhost'
# 刷新权限
flush privileges;
注意:mysql 5.7版本还要将 my.ini
中的 skip-grant-tables
再注释掉