MySQL Database installation
I. Overview
1. What is a database?
A: The warehouse of the data, which is called the database
2. What is MySQL, Oracle, SQLite, Access, MS SQL Server, etc.?
A: They are all software and have two main functions:
A. Saving data to a file or memory
B. Receive a specific command, and then perform the appropriate action on the file
MySQL is a relational database management system developed by the Swedish MySQL AB company, currently owned by the Oracle company. MySQL's most popular relational database management system, MySQL is one of the best RDBMS (relational database Management system, relational databases management systems) application software in WEB applications.
PS: If you have the above software, do not have to create files and folders yourself, but instead of directly passing commands to the above software, let them for file operations, they collectively referred to as the database management system (Dbms,database Management Systems)
3. What is SQL statement?
A: The above mentioned MySQL and other software can accept the command, and do the appropriate action, because the command can contain delete files, get the contents of the file, and so many operations, for the written command is the SQL statement. SQL is the abbreviation for structured language (structured Query Language), which is a language specifically designed to communicate with a database.
Ii. download and install MySQL database security
To use MySQL to store and manipulate data, you need to do a few things:
A. Installing the MySQL server
B. Installing the MySQL Client
B. "Client" Connection "server Side"
C. "Client" sends a command to the "server-side MySQL" Service to accept the command and perform the appropriate operation (increase and deletion of the search, etc.)
Official Download URL: http://dev.mysql.com/downloads/mysql/
Window version Installation
1, download, MySQL Community Server 5.7.16 version
2. Decompression
If you want MySQL to be installed in the specified directory, then move the extracted folder to the specified directory, such as: e:\
Files in the folder after decompression
Installing and starting MySQL
MySQL after extracting the bin directory has a lot of executable files
1. Initialization
CMD runs as Administrator
Go to initialization directory
// CD E:\mysql-5.7.16-winx64\bin C:\WINDOWS\system32>cd E:\mysql-5.7.16-winx64\bin
Initializing data after entering the directory
// mysqld--initialize-insecure E:\mysql-5.7.16-winx64\bin>mysqld--initialize-insecure
Note: There is no return information at this time to see if the Data folder is automatically generated under the E:\mysql-5.7.16-winx64 directory, and if this folder is generated and the folder contains data, it indicates that the initialization was successful.
Data folder contains
Start the MySQL service
// mysqld E:\mysql-5.7.16-winx64\bin>mysqld
Note: The CMD terminal cannot be operated at this time, directly close the cmd Terminal window
Re-run CMD Terminal as administrator into the e:\mysql-5.7.16-winx64\bin> directory
Start the MySQL client and connect to the MySQL service
The default password is not set to the root account due to the "mysqld--initialize-insecure" command used during initialization
// Enter mysql-u root-p in the e:\mysql-5.7.16-winx64\bin> directory E:\mysql-5.7.16-winx64\bin>mysql-u root-p//Enter password: Prompt Please enter password, direct enter
To this end, the MySQL server has been successfully installed and the client is ready to connect, and in the future to operate mysql
-
u root
-
p
MySQL, just repeat the above steps. However, repeated access to the executable directory is cumbersome, if you want to be easy to operate in the future, you can do the following.
Adding environment variables
Add the MySQL executable to the environment variable to execute the command
【环境变量】
-
-
》【在第二个内容框中找到 变量名为Path 的一行,双击】
-
-
> 【将MySQL的
bin
目录路径追加到变值值中,用 ; 分割】
// such as: C:\Program Files (x86) \parallels\parallels tools\applications;%systemroot%\system32;%systemroot%;%systemroot%\ System32\wbem;%systemroot%\system32\windowspowershell\v1.0\; C:\Python27; C:\Python35; C:\mysql-5.7.16-winx64\bin
As a result, you do not need to enter the bin directory to start the service and connect at a later time, just:
// start the MySQL service, enter in the terminal // connect MySQL service at terminal input:mysql-u root-p
Making a MySQL service into a Windows service
The previous step solves some problems, but is not exhaustive, because the current terminal will be stuck while executing "MYSQD" to start the MySQL server, then do the setup to resolve the problem:
// Create a Windows service for MySQL, execute this command at the terminal:"E:\mysql-5.7.16-winx64\bin\mysqld"--// Remove the MySQL Windows service and execute this command at the terminal:"E:\mysql-5.7.16-winx64\bin\mysqld"--remove
After registering as a service, you only need to execute the following command when you start and close the MySQL service later:
// start the MySQL service // close MySQL service net stop MySQL
Uninstall MySQL is the CD to the bin directory to execute mysqld--remove
Detect installation, enter MySQL--version
Enter exit exit
Linux version installation
Online installation
Installation:
Yum Install Mysql-server
Service-side startup
Mysql.server start
Client connections
// Connection: Mysql-h host-u User-p // Common error:error 2002 (HY000): Can ' t connect to local MySQL serve R through socket '/tmp/mysql.sock ' (2), it means that the MySQL server daemon (Unix) or service (Windows) are not Runn ing.//exit: quit or Control+d
Offline Installation "recommended"
1, unzip the mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz, and copy to the/usr/local/mysql directory
Extract:
TAR-ZXVF mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz
Copy:
sudo cp-r mysql-5.7.16-linux-glibc2.5-x86_64/usr/local/mysql
2. Add System MySQL Group and MySQL user
Add System MySQL Group
sudo groupadd MySQL
Add MySQL User
sudo useradd-r-g MySQL MySQL
View available when add is complete id mysql
3. Install the database
Switch to the/usr/local/mysql directory
Cd/usr/local/mysql
Modify current directory owner for MySQL user
sudo chown-r mysql:mysql.
Install the database (version 5.7 installation is not recommended to use mysql_install_db to install, but use mysqld)
Bin/mysqld--initialize--user=mysql--basedir=/usr/local/mysql--datadir=/usr/local/mysql/data
Temporary password: Xk?hs6ohu
Execute the following command to create the RSA private key
sudo bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data
Modify the current directory owner to be the root user
sudo chown-r root:root.
Modify the current data directory owner as a MySQL user
sudo chown-r mysql:mysql data
4. Configure MY.CNF and Boot
CD support-Filessudo cp my-default. cnf/etc//etc/init.d/mysqlsudo vim/etc/init.d/mysql # #修改basedir = own path to modify datadir= own path
Save and Exit VI after the modification is complete :wq!
VI Command:
Press ESC to jump to command mode, and then: W Save the file but do not exit vi:w. File to save the modification to file, do not exit Vi:w! force save, do not eject Vi:wq save file and exit Vi:wq! force save file and Exit VI Q: Do not save file, Exit Vi:q! do not save the file, Force exit Vi:e! Discard all changes and edit from the last time the file was saved
Modify MY.CNF
sudo vim/etc/my.cnf
[mysqld] character-set-server=UTF8 datadir=/home/mysql/mysqldata basedir=/usr/local/mysql socket =/var/lib/mysql/mysql.sock
Save and exit
5. Start MySQL
Service MySQL Start
Log in to MySQL and set up a remote connection
Mysql-u User-* * to ' user ' @ '% ' identified by ' password ' with GRANT option;flush privileges;
Section No. 275, MySQL database installation and introduction