MySQL8快速安装以及配置小技巧

安装

首先去官网下载,地址是这个 我选择的是Windows (x86, 64-bit), ZIP Archive。解压到一个目录,然后按照下面的命令执行

cd /d/mysql-8.2.0-winx64/bin
./mysqld --initialize --console
# 上面这个命令执行完成之后控制台会输出临时密码,注意把这个密码保存下来

./mysqld &
cd /d/mysql-8.2.0-winx64/bin
./mysql -u root -p
# 这里输入上面保存的密码

注:我的操作系统是windows,但是我安装了gitbash,上面的命令是在gitbash终端执行的

成功登录之后再操作数据库之前需要先修改密码

alter user user() identified by 'root';
exit

我这里是把密码改成了root,然后退出。

到此。恭喜完成了安装!!!

启动时的参数设置

命令行执行

mysqld --verbose --help

可以看到启动支持的命令选线。这里挑选几个常用的介绍一下

  • --console输出内容到控制台 Write error output on screen; don’t remove the console window on windows
  • --initialize 初始化数据库,创建一个超级用户(root)并设置密码 Create the default database and exit. Create a super user with a random expired password and store it into the log.
  • --initialize-insecure 空密码 Create the default database and exit. Create a super user with empty password.
  • --datadir 数据文件存储位置 Path to the database root directory
  • --port 指定客户端连接要使用的端口

指定数据存储位置,安装一次,拥有多个数据库

通过上述参数可以方便的指定数据存储位置,达到安装一次,拥有多个数据库的目的。举个例子:

# 指定一个空文件目录进行初始化。虽然是windows系统,但是我命令是在gitbash中执行的,索引文件路径是unix风格
mysqld --console --initialize-insecure --datadir='/e/tmp/test'

# 使用初始化的文件启动服务
mysqld --datadir='/e/tmp/test' &
mysql -u root  # 直接回车就进入客服端了

你可能感兴趣的:(数据库,mysql)