[Switch] Ubuntu MySQL uses apt-get install installation directory

1).   The mysql installation layout under ubuntu:
/usr/bin client program and mysql_install_db
/var/lib/mysql database and log files
/var/run/mysqld server
/etc/mysql configuration file my.cnf
/usr/share/mysql character set, benchmark program and error messages
/ etc/init.d/mysql start mysql server
2).   Set the mysql server to automatically start and close with the power on and off:
System -> System Management -> Service
After going to the "Service Settings" window, activate the mysql database service.
3).   Modify the storage directory of the mysql database file:
 
MySQL's default data file storage directory is /var/lib/mysql. If you want to move the directory to /home/data, you need to do the following steps:
1. Create a data directory in the home directory
cd / home
mkdir data
2. Stop the MySQL service process:
mysqladmin -u root -p shutdown
3. Move the entire directory /var/lib/mysql to /home/data
mv /var/lib/mysql /home/data/
This moves the MySQL data files to /home/data/mysql
4. Find the my.cnf configuration file
If there is no my.cnf configuration file in the /etc/ directory, please go to /usr/share/mysql/ to find the *.cnf file, copy one of them to /etc/ and rename it to my.cnf). The command is as follows:
[root@test1 mysql]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
5. Edit the MySQL configuration file /etc/my.cnf
To ensure that MySQL can work properly, you need to specify the location where the mysql.sock file is generated. Modify the value to the right of the equal sign in the line socket=/var/lib/mysql/mysql.sock: /home/mysql/mysql.sock. The operation is as follows:
vi my.cnf (edit my.cnf file with vi tool, find the following data and modify it)
# The MySQL server
[mysqld]  port = 3306
#socket = /var/lib/mysql/mysql.sock (original content, comment this line with "#" for safety)
socket = /home/data/mysql/mysql.sock (plus this line)
6. Modify the MySQL startup script /etc/init.d/mysql
Finally, you need to modify the MySQL startup script /etc/init.d/mysql, and change the path to the right of the equal sign in the datadir=/var/lib/mysql line to your current actual storage path: home/data/mysql.
[root@test1 etc]# vi /etc/init.d/mysql
#datadir=/var/lib/mysql (comment this line)
datadir=/home/data/mysql (plus this line)
7. Restart the MySQL service
/etc/init.d/mysql start
Or restart Linux with the reboot command
If it works normally the move is successful, otherwise check it against the previous 7 steps. Also pay attention to the owner and permissions of the directory.
4).   Configure the INNODB storage engine of the mysql database:
1. Check the mysql storage engine situation: Log in to the mysql database and enter the show engines; command at the mysql> prompt. Found: InnoDB | YES, indicating that this mysql database server supports the InnoDB engine.
2. Set InnoDB as the default engine: add the sentence default-storage-engine=INNODB under [mysqld] in the configuration file my.cnf and save it.
3. Restart the mysql server: mysqladmin -u root -p shutdown (enter), sudo /etc/init.d/mysql start (enter).
4. Log in to the mysql database and enter the show engines; command at the mysql> prompt. If InnoDB |DEFAULT appears, it means that we successfully set InnoDB as the default engine.
ps:   Here I use the restart command sudo /etc/init.d/mysql restart, and an error message appears, so I use the stupid method of shutting down the service and restarting it (step 3).
 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326608465&siteId=291194637