MySQL installation is not as if SQL Server is installed by default in a directory, its database files, configuration files and command files in different directories, it is important to understand these directories, especially for the Linux beginners, because the Linux itself directory structure is more complex, If you don't know the MySQL installation directory then you can't talk about deep learning.
Here are a few of the directories to look at.
1. Database Directory
/var/lib/mysql/
2. Configuration files
/usr/share/mysql (mysql.server command and configuration file)
3. Related commands
/usr/bin (Mysqladmin mysqldump and other commands)
4. Startup script
/etc/rc.d/init.d/(startup script file for MySQL directory)
Modify Login Password
MySQL does not have a password by default, the importance of increasing the password is self-evident.
1. Command
usr/bin/mysqladmin-u root password ' new-password '
Format: Mysqladmin-u username-P Old password password new password
2. Example
Example 1: Add a password to root 123456.
Type the following command:
[Email protected] local]#/usr/bin/mysqladmin-u root password 123456
Note: Because Root does not have a password at the beginning, the-p old password can be omitted.
3. Test whether the modification is successful
1) Login without password
[[email protected] local]# MySQL
ERROR 1045:access denied for user: [email= ' [email protected] ' [email protected] ' [/email] (Using password:no)
An error is displayed stating that the password has been modified.
2) Log in with the modified password
[Email protected] local]# mysql-u root-p
Enter Password: (Enter the modified password 123456)
Welcome to the MySQL Monitor. Commands End With; or G.
Your MySQL Connection ID is 4 to server Version:4.0.16-standard
Type ' help ', ' or ' h ' for help. Type ' C ' to clear the buffer.
Mysql>
Success!
This is done by changing the password with the Mysqladmin command, or by modifying the library.
Start and stop
1. Start
After the MySQL installation is complete, start the file MySQL in the/ETC/INIT.D directory and run the following command when it needs to start.
[[email protected] init.d]#/etc/init.d/mysql start
2. Stop
/usr/bin/mysqladmin-u root-p shutdown
3. Auto-start
1) See if MySQL is in the auto-start list
[Email protected] local]#/sbin/chkconfig–list
2) Add MySQL to your system's start-up service group
[[email protected] local]#/sbin/chkconfig–-add MySQL
3) Remove MySQL from the Startup service group.
[[email protected] local]#/sbin/chkconfig–-del MySQL
Change MySQL Directory
The default data file storage directory for MySQL is/var/lib/mysql. The following steps are required if you want to move the directory to/home/data:
1. Set up the data directory in the home directory
Cd/home
mkdir data
2. Stop the MySQL service process:
Mysqladmin-u root-p shutdown
3. Move/var/lib/mysql Entire directory to/home/data
mv/var/lib/mysql/home/data/
This will move the MySQL data file to/home/data/mysql.
4. Locate the MY.CNF configuration file
If there is no MY.CNF configuration file under the/etc/directory, locate the *.cnf file under/usr/share/mysql/, and copy one of them to/etc/and rename it to MY.CNF). The command is as follows:
[Email protected] mysql]# CP/USR/SHARE/MYSQL/MY-MEDIUM.CNF/ETC/MY.CNF
5. Edit the MySQL configuration file/etc/my.cnf
To ensure that MySQL works correctly, you need to indicate where the Mysql.sock file is generated. Modify the value to the right of the equals sign in a socket=/var/lib/mysql/mysql.sock line
As:/home/mysql/mysql.sock. The operation is as follows:
VI my.cnf (Edit the My.cnf file with VI tool, find the following data to modify)
# The MySQL server
[Mysqld]
Port = 3306
#socket =/var/lib/mysql/mysql.sock (original content, in order to be more secure with "#" Comment this line)
Socket =/home/data/mysql/mysql.sock (plus this line)
6. Modify MySQL startup script/etc/rc.d/init.d/mysql
Finally, you need to modify the MySQL startup script/etc/rc.d/init.d/mysql, the path to the right of the equal sign in the Datadir=/var/lib/mysql line is changed to your current actual storage
Drop path: Home/data/mysql.
[Email protected] etc]# Vi/etc/rc.d/init.d/mysql
#datadir =/var/lib/mysql (Note this line)
Datadir=/home/data/mysql (plus this line)
7. Restart MySQL Service
/etc/rc.d/init.d/mysql start
or restart Linux with the reboot command
If the work is moving properly, otherwise check the previous 7 steps.
In order to be able to log on with the root user on other computers, the following actions are required:
1, [[email protected]][email protected][/email] mark>mysql-h localhost-u root
This should allow access to the MySQL server
2, Mysql>grant all privileges on * * to [email= ' root ' @ '% '] ' root ' @ '% ' [/email] with GRANT OPTION
Give any host access to data
3, Mysql>flush privileges
Changes take effect
4, Mysql>exit
Log out of MySQL server
MySQL default installation directory description