一.新增my.ini
文件内容如下:
# 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]
#skip-grant-tables
# 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 = .....
# datadir = .....
# port = .....
# server_id = .....
basedir ="C:\MySql\mysql-8.0.20-winx64 # 设置mysql的安装目录
datadir ="C:\MySql\mysql-8.0.20-winx64\data" # 设置mysql数据库的数据的存放目录,必须是data,或者是//xxx/data
# 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
#服务端的编码方式
character-set-server=utf8mb4
[client]
#客户端编码方式,最好和服务端保存一致
loose-default-character-set=utf8mb4
[WinMySQLadmin]
Server = "C:\MySql\mysql-8.0.20-winx64\bin\mysqld.exe"
二.修改环境变量
计算机——属性——高级系统设置——环境变量
选择path新增mysql安装bin目录路径
三.初始化
在bin目录下cmd运行
3.1.mysqld --initialize --console
执行过后找到A temporary password is generated for root@localhost: 这句,localhost后面就是自己的初始化密码。
若此时弹出缺少MSVCP140.dll,安装VC_redist.exe。
若报错ound option without preceding group in config file:,将my.ini文件编码方式由utf-8改为ANSI
3.2.net start mysql
启动服务,则输入
若服务名无效
输入 mysqld --install
若要删除mysql,可执行命令
mysqld --remove mysql
3.3.mysql -u root -p
进行登录数据库,这时提示需要密码,然后就是用上面的密码登录
3.4.修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
或
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
修改密码为:123456
四.新增账户
create user 'demo'@'%' identified with mysql_native_password BY '123456';
五.修改权限:
grant all privileges on *.* to 'demo'@'%' with grant option;
六.刷新
flush privileges;
七.备份
mysqldump -udemo -p123456 demo table >baktable.sql;
--single-transaction 锁定数据库防止其他事物操作导致数据不一致
### 七.导入库
source
七.删除库
drop database demo;