Mysql database installation, multiple versions, manual configuration, password change
Take 5.7 and 8.0 as an example
Historical version address of mysql official website:
https://downloads.mysql.com/archives/community/
Download the required version
Mysql5.7 manual configuration installation
1. Create a new configuration file in the decompressed foldermy.ini
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
#设置3306端口
port=3306
# 设置mysql的安装目录
basedir=D:\mysql\mysql-5.7.36-winx64
# 允许最大连接数
max_connections=200
# 服务端使用的字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
Modify the value of basedir to your own decompression directory
2. Start the command line as an administrator and enter the bin directory of mysql. It must be a command prompt running as an administrator.
3. Initialize mysql
mysqld --initialize-insecure
After completion, there will be an additional data directory in the root directory. The -insecure parameter ignores security. The initialized mysql has no root password, and the password is set manually
4. Install (register) mysql service
安装
mysqld -install mysql5.7(可选填、服务名)
移除
mysqld -remove 服务名
If you do not set the service name, the default is: mysql. If you have multiple mysql installations, you can write the version number for easy identification
You can already view the installed mysql service in the computer management (right click on the start button)
5. To start mysql, you can start it in the computer management, or you can start it manually through the command
net start "mysql5.7"
6. Log in to mysql and change the password
mysql -uroot
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
- You can write two bat files to start and stop the mysql service, but you need to run the batch file as an administrator to start the service, so you can add a command to escalate the privilege
@echo off
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
pushd "%CD%"
CD /D "%~dp0"
:begin
net start "mysql5.7"
The last sentence can be changed to a command to shut down the service:
net stop "mysql5.7"
Mysql8.0 manual configuration installation
The installation method is the same as mysql5.7, pay attention to modify my.ini
the installation path and port inside, if you want to run different versions of mysql at the same time, you only need to set the port to be different. Log in to
mysql:
mysql -P端口号 -uroot
Steps to modify the password:
there is no root password after the default installation, you only need to set it:
alter user 'root'@'localhost' identified by '新密码';
flush privileges;
If you need to change the password during use, first set it to empty and then set the password:
update user set authentication_string='' where user='root';
Remember to like it!