安装mysql-8.0.31-winx64【纯操作记录】

发布于:2024-05-06 ⋅ 阅读:(34) ⋅ 点赞:(0)

【一、安装MySQL操作】

  • 1、设置环境变量:配置(MYSQL_HOME 及 PATH)
MYSQL_HOME=你的MySQL位置
PATH:%MYSQL_HOME%;
  • 2、测试输出:输入mysql测试看输出内容
C:\Users\Administrator>mysql
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost:3306' (10061)
  • 3、初始化数据:

打开命令行窗口,使用管理员身份运行命令行窗口

mysqld --initialize-insecure
  • 4、安装服务:
语法:
	mysqld install MySQL服务名称
    mysqld install MySQL8.0.31   -- 指定mysql服务名称为MySQL8.0.31
注意事项:
	如果不指定服务名称,默认为MySQL

示例: 
    mysqld install -- 默认服务名称为MySQL
  • 5、开启服务:
net start mysql  // 启动mysql服务
net stop mysql  // 停止mysql服务
  • 6、设置root用户密码

重开一个cmd命令行窗口,输入下面的命令进行密码的设置

语法:	
	mysqladmin -u 用户名 password 用户密码 

示例:
	mysqladmin -u root password root
  • 7、测试是不是可以登录,能不能查看mysql数据库版本
C:\Users\Administrator>mysql -uroot -p1234
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 8.0.31 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
  • 8、退出mysql,exit或quit

可以使用exit命令退出

mysql> exit
Bye

C:\Users\Administrator>

也可以用quit命令退出

mysql> quit
Bye

C:\Users\Administrator>

【二、卸载MySQL操作】

  • 1、停止服务
net stop mysql服务名称
  • 2、移除服务项
mysqld -remove mysql服务名称
  • 3、删除文件
【1】删除mysql安装目录文件
【2】删除mysql有关的环境变量

【三、修改用户密码】

参考地址:【修改root用户密码】 https://blog.csdn.net/qq_40757240/article/details/118068317

前提条件:需要先知道用户的密码,如果不知道就不用看这个操作了

  • 1、先登录要改密码的用户
语法:
	mysql -u 用户名 -p旧密码 -P端口号
注意事项:
	-p是小写的,用来指定登录密码,不要空格
	-P是大写的,用来指定端口号,不要空格(默认端口为3306),如果有多个数据库,则需要设置端口号;如果默认数据库端口3306,可以不写


示例:	
	mysql -u root -p1234 -- 连接mysql数据库端口号3306,登录用户root,密码1234
	mysql -u admin -p123456 -P3310 -- 连接mysql数据库端口号3310,登录用户admin,密码123456
  • 2、修改用户密码为xxx

输入你的新密码

语法:
	ALTER USER '用户名'@'localhost' IDENTIFIED BY '新密码';

示例:
	ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

【四、查看MySQL配置】

看mysql安装的位置

mysql> SHOW VARIABLES LIKE 'basedir';
+---------------+------------------------------------+
| Variable_name | Value                              |
+---------------+------------------------------------+
| basedir       | D:\apps\MySQL\mysql-8.0.31-winx64\ |
+---------------+------------------------------------+
1 row in set, 1 warning (0.00 sec)

mysql>

看data数据文件存放的位置

mysql> SHOW VARIABLES LIKE 'datadir';
+---------------+-----------------------------------------+
| Variable_name | Value                                   |
+---------------+-----------------------------------------+
| datadir       | D:\apps\MySQL\mysql-8.0.31-winx64\data\ |
+---------------+-----------------------------------------+
1 row in set, 1 warning (0.01 sec)

mysql>

查看my.ini或my.cnf位置指定的位置路径

C:\Users\Administrator>mysqld --help --verbose
mysqld.exe  Ver 8.0.31 for Win64 on x86_64 (MySQL Community Server - GPL)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Starts the MySQL database server.

Usage: mysqld.exe [OPTIONS]
NT and Win32 specific options:
  --install                     Install the default service (NT).
  --install-manual              Install the default service started manually (NT).
  --install service_name        Install an optional service (NT).
  --install-manual service_name Install an optional service started manually (NT).
  --remove                      Remove the default service from the service list (NT).
  --remove service_name         Remove the service_name from the service list (NT).
  --enable-named-pipe           Only to be used for the default server (NT).
  --standalone                  Dummy option to start as a standalone server (NT).


Default options are read from the following files in the given order:
C:\Windows\my.ini C:\Windows\my.cnf C:\my.ini C:\my.cnf D:\apps\MySQL\mysql-8.0.31-winx64\my.ini D:\apps\MySQL\mysql-8.0.31-winx64\my.cnf

【五、创建配置】

  • 1、在mysql的目录下创建,my.ini 配置文件


配置文件的内容

[mysql]
default-character-set=utf8

[mysqld]
character-set-server=utf8
group_concat_max_len = 1024000
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

  • 2、重启服务(先停止再启动)
// 停止mysql服务
net stop mysql  

// 启动mysql服务
net start mysql