01 MySQL database installation (Windows+Mac)

Posted by pablocullen on Fri, 18 Feb 2022 12:54:26 +0100

Python wechat ordering applet course video


Python actual combat quantitative transaction financial management system

Catalogue* MySQL database installation
+ Windows
- 1. Introduction to main versions
- 2. Software download
- 3. Introduction to document directory
- 4. Use
* 4.1 configuring environment variables
* 4.2 login
+ Make MySQL server self startup
+ Run MySQL
* 4.3 password modification
+ The password needs to be set for the administrator user
+ How to solve the problem of forgetting the password (understand)
+ Mac
- 1. Download and install (version 8.0.11)
- 2. Start MySQL
* Terminal startup and shutdown MySQL
- 3. Log in to MySQL

MySQL database installation


MySQL for Windows is the best installation. It can be done without hands, with eyes closed, and with respect to the screen,

1. Introduction to main versions

 5.6:More frequently used versions
 5.7:Currently transitioning version
 8.0:Current latest version
"""The main difference between different versions lies in the underlying logic SQL The statement is as like as two peas."""
# You can use version 5.6 in the learning phase (if you have downloaded other versions, it's OK)
But it's 2022. Do it 8.0 Or broad to drop,

2. Software download

Visit the official website:https://www.mysql.com/
step:DOWNLOADS >>> MySQL Community (GPL) Downloads >>> MySQL Community Server >>> Archives
 Select the version to download the compressed package(Customer service end),click'Download'Download it.
After downloading, see below.

3. Introduction to document directory

bin folder:mysqld.exe Server
 mysql.exe Customer service end
data folder:Data to be saved during storage and use
my-default.ini:configuration file

4. Use

4.1 configuring environment variables

1) Right click [my computer] > > > [properties] > > > > [advanced system settings] > > > [advanced] > > > > [environment variables] > > > on the desktop, and then enter the [environment variables] page

2) Select [Path] in [system variable], double-click to enter the editing page of [Path], and then click [new] > > > [paste file Path] > > > [OK].

After configuring the environment variables above, set the login account of MySQL below.

4.2 login

Be sure to start the server first and then the client, and it is best to use administrator cmd in the early operation.

Make MySQL server self startup

1) Use the cmd command run by the administrator and enter the command to create the system service first.

mysqld --install

2) Run services with win+r MSc, enter the service list, find MySQL and right-click to start it. In this way, it will start automatically.

MySQL server command on and off

Start service: net start mysql
 Out of Service: net stop mysql


1) Run the cmd command with the administrator and enter the command mysql -uroot -p for the first time. Will run MySQL server.
2) Login account

 mysql Visitor mode login
 mysql -u user name -p password # Account login (local use)
 mysql -hIP address -P Port number -u user name -p password # Full command
 """First login root If the user does not have a password, just press enter continuously"""

4.3 password modification

The password needs to be set for the administrator user
Mode 1:Directly in cmd Use in window mysqladmin command
 mysqladmin -uroot -p Original password password New password
 mysqladmin -uroot -p password 123
 mysqladmin -uroot -p123 password 666
 Mode 2:Directly modify the password of the current login user in login status
 set password=PASSWORD('password')

How to solve the problem of forgetting the password (understand)
 Mode 1:There is no data in the database in the early stage. Just start again!!!
 Mode 2:Get to know
 1.Close the server
 2.Restart the server by skipping the authorization table
 You only need to provide a user name to log in
 mysqld --skip-grant-tables
 3.Log in as Administrator
 mysql -uroot -p
 4.Modify administrator user password
 update mysql.user set password=password(123) where user="root" and host="localhost";
 5.Close the server and start it normally
 ctrl + C
 net start mysql
 6.Log in with the modified password


1. Download and install (version 8.0.11)

Download address of official website: https://dev.mysql.com/downloads/mysql/https://dev.mysql.com/downloads/mysql/

Steps: DOWNLOADS >>> MySQL Community (GPL) Downloads >>> MySQL Community Server >>> Archives
 Then select the version to download and click'Download'Download it.

I chose to install macOS 10.13 64 bit DMG package

2. Start MySQL

After MySQL is installed, open the system preferences and you will see

Double click to enter mysql startup

Terminal startup and shutdown MySQL

start-up MySQL service sudo /usr/local/MySQL/support-files/mysql.server start

stop it MySQL service sudo /usr/local/mysql/support-files/mysql.server stop

restart MySQL service sudo /usr/local/mysql/support-files/mysql.server restart

3. Log in to MySQL

After installation, log in to MySQL.
I encountered an error here.

Login instruction: mysql -uroot -p
 After I entered the run, the problem occurred:
MySQL You will be asked to enter a default password, but when you log in with the default password on the terminal, you will always be prompted with an authorization failure error:
Access denied for user 'root'@'localhost' (using passwor)

Resolve error reporting
PS: This is because the password is not set for the root role. Let's set it below.

1. Open terminal stop mysql
sudo /usr/local/mysql/support-files/mysql.server stop

2. Skip login mode, start and enter mysql
sudo mysqld\_safe --user=mysql --skip-grant-tables --skip-networking

See the figure below

3. Open another terminal window
 Knock in mysql -u root -p Command and then enter. When you need to enter a password, press directly Enter Key, you can log in to the database without password.

See the figure below

4. modify root password
 There's a problem! Errors are reported in the way of password reset on the Internet:
set password for 'root'@'localhost'=password('123');

As shown in the following figure, syntax errors will be reported whether it is changed to uppercase or lowercase
ERROR 1064 (42000): You have an error in your SQL syntax;

5. solve root Password error

Because it's a new version 8.0 The old version of the syntax for changing passwords is no longer applicable, mysql 5.7.9 It was abandoned later password Fields and password()Function;
mysql>use mysql;


mysql>ALTER user 'root'@'localhost' IDENTIFIED BY 'newpassward'
**PS: The password here should contain 8 uppercase characters+a lowercase letter+Special characters+Digital password, and then you will be prompted to modify the password successfully!**
mysql>quit; >>> sign out mysql;

Note: the original skip-grant-tables The terminal should be closed, preferably in kill fall mysql Process;

Then restart mysql;

Finally, use it directly mysql -uroot -p Enter the password just set to log in normally!

PS: if there are other problems, please check the official website documents directly, which is much more reliable than the solutions on the Internet!
The website is lost to you, hey hey!


[the external chain image transfer fails. The source station may have anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-z4rlf3vm-1645135695366)( https://blog.csdn.net/panda-xin/p/15905499.html )]Pand_ Xin article link: https://blog.csdn.net/panda-xin/p/15905499.html About bloggers: comments and private messages will be replied at the first time. perhaps Direct private letter I. Copyright notice: all articles on this blog are in English unless otherwise stated BY-NC-SA License agreement. Reprint please indicate the source! Support bloggers: if you think the article is helpful to you, you can click * * [recommend] (javascript:void(0) in the lower right corner of the article) 😉]** once. Your encouragement is the biggest motivation of bloggers!

Topics: Python Windows Database MySQL computer