REVIEW:
Our daily study may need to install the MySQL service locally, also encountered a small partner to explore questions about Windows system installed MySQL. Here suggest that you install MySQL5.7 version, of course, I want to try the 8.0 version of the students also can refer to the installation. This article to MySQL5.7.23 version, for example, a step by step as we summarize the installation steps, we want to help!
1. Check and uninstall the original version
Under our system, we can check the service determines that there is no case had two MySQL installed, open the Windows system services are:
- Right-click on My Computer / Computer, click Manage to open Computer Management, select services and applications - services.
- Use the shortcut command: win + r key while pressing Enter services.msc in the Run window to open the service.
Open the System Services page below, you can see my computer has been installed MySQL, here I uninstall it, if your computer does not have MySQL service is not required to operate this step.
Now we open the cmd command line to uninstall MySQL:
- Stop MySQL service
- Uninstall MySQL
2. Download the MySQL installation package
download link:
https://downloads.mysql.com/archives/community/
Select the Windows download version 5.7.23
3. Extract the installation package and configure the environment variables
The compression bag on a suitable disk decompression, I am here on the E drive, unzip the folder recommend rename mysql5.7.23.
Before the proposed installation to configure the environment variables:
Right-click My Computer / Computer, click Properties to open the Advanced System Settings, click Environment Variables.
Variable Name: MYSQL_HOME
variable values: E: \ mysql5.7.23
path was added:% MYSQL_HOME% \ bin
4. Create a data directory and configuration files
This version of MySQL does not create data directory and my.ini. Create a data directory under MYSQL_HOME directory, it is recommended data directory to E: \ mysql5.7.23 \ data. In addition, create Uploads directory as the MySQL import export directory. my.ini put the proposal under MYSQL_HOME directory, simple configuration, see:
[mysqld]
port=3306
character_set_server=utf8
basedir=E:\mysql5.7.23
datadir=E:\mysql5.7.23\data
server-id=1
sql_mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
lower_case_table_names=1
innodb_file_per_table = 1
log_timestamps=SYSTEM
log-error = error.log
slow_query_log = 1
slow_query_log_file = slow.log
long_query_time = 5
log-bin = binlog
binlog_format = row
expire_logs_days = 15
log_bin_trust_function_creators = 1
secure-file-priv=E:\mysql5.7.23\Uploads
[client]
default-character-set=utf8
After the completion of our directory structure become so
5. initialize the database
cmd command line to enter the E: \ mysql5.7.23 \ bin directory, execute mysqld --initialize-insecure
after the execution is completed, the data in the directory will generate a lot of files.
6. register and start MySQL service
Execute mysqld -install MySQL57 installation services (install followed by the name of the service, we are here to MySQL57 as the service name mysql5.7) net start MySQL57 start the MySQL service.
7. Log in and change your password
To remind you that due to the initial setting or differences between versions, some versions after installation is complete root password is empty, some are temporary password, we need to see the error log logs tips.
Open the error log and found that I have here is a blank password.
Now we command line login modifications Password:
If you need to configure remote access to the root user, you can execute the following statement:
Then we can log in using tools such as Navicat!
8. supplied backup script
It presented additional logical backup script oh, if you want to back up every day, can be added to script scheduled tasks, the timing to perform every day.
We can create a MySQLdata_Bak under the E disk directory, create a directory to store the backup files mysql_backup this directory, mysql_bak.bat backup script, the script reads as follows (automatically delete backup files older than 7 days):
rem auther:wang
rem date:20190526
rem ******MySQL backup start********
@echo off
forfiles /p "E:\MySQLdata_Bak\mysql_backup" /m backup_*.sql -d -7 /c "cmd /c del /f @path"
set "Ymd=%date:~0,4%%date:~5,2%%date:~8,2%0%time:~1,1%%time:~3,2%%time:~6,2%"
"E:\mysql5.7.23\bin\mysqldump" -uroot -p123456 -P3306 --default-character-set=utf8 -R -E --single-transaction --all-databases > "E:\MySQLdata_Bak\mysql_backup\backup_%Ymd%.sql"
@echo on
rem ******MySQL backup end********
Overall directory structure is as follows, mysql_bak.bat script to back up all of our database, double-click to run under.