首页 > 技术文章 > MySQL绿色版安装【一键安装脚本】

miskis 2016-10-13 16:54 原文

Linux安装地址:https://www.cnblogs.com/miskis/p/6038645.html
一键安装卸载批处理脚本:https://share.weiyun.com/VwOhWYWV

以管理员运行脚本,按提示操作修改登录密码即可!

一、绿色版安装

1、下载MySQL 8.0.16,地址:http://dev.mysql.com/downloads/mysql/ (选择32位或者64位版本需根据自身PC情况)

2、解压到你自己的磁盘

3. 配置Path路径:系统属性 => 高级 => 高级 => 系统变量 => path后添加 (如:D:\Tools\mysql-8.0.16-winx64\bin)

4. 在mysql根目录下新建 my.ini,此文件是初始化信息(默认mysql根目录不存此文件):

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
basedir = D:\Tool\mysql-8.0.20-winx64
datadir = D:\Tool\mysql-8.0.20-winx64\data
port = 3306
# server_id = .....


# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
# Windows下忽略大小写
lower_case_table_names=2 
[WinMySQLadmin]  
Server = D:\Tool\mysql-8.0.20-winx64\bin\mysqld.exe

5. 以管理员身份打开“命令行窗口”,输入命令 mysqld --initialize-insecure --user=mysql

执行这条命令需要花一定的时间(大概几秒,根据电脑情况),不会有返回结果,但是可以在MySQL的安装目录下看到,原本为空的data文件夹里面有了许多文件和文件夹

6. 输入命令mysqld -install ,当看到Service successfully installed时,表示Mysql服务添加成功

7. 输入命令net start mysql,启动Mysql服务

8.登录mysql后,修改密码(默认密码为空)

 (1)以管理员身份打开“命令行窗口”,输入mysql -uroot -p并按下回车键

 (2)在弹出Enter password: 时,继续按下回车键,即可登录mysql

 (3)输入命令use mysql;

 (4)输入命令ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码'; (注意末尾要有分号)

 (5)输入命令flush privileges; 

 (6)输入命令exit;

9.解决远程无法登录错误

//使用root登录mysql
mysql -u root -p
//切换数据库
mysql>use mysql;
//修改数据
mysql>update user set host = '%' where user = 'root';
//查询数据
mysql>select host, user from user;
//允许远程使用root账号登录
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
//刷新权限
mysql>flush privileges;

mysql 8.0.25 版本允许远程登录连接命令:

进入mysql控制台,

1、use mysql;

2、update user set host='%' where user='root';

3、flush privileges;

4、alter user 'root'@'%' identified by '12345678' password expire never;

5、alter user 'root'@'%' identified with mysql_native_password by '12345678';

6、flush privileges;

 

到处安装完成!

 

推荐阅读