Modify the default storage path of MySQL
MySQL is a good choice for storing data in Linux. The default storage path of MySQL is/var/lib/mysql. In the past, the database was not very large, with a total size of around 10 Gb, and there was no pressure on the default path. But today, because a new database is imported, the data is 30 + GB, and it is a tragedy in an instant, because I have not prepared enough hard disk partition space for the/directory. Therefore, it is the most effort-saving option to modify the configuration and migrate the database storage path to the appropriate place.
Stop mysql service and prepare data
Because it was modified in half, there was some historical data. The database service should be stopped first. I use Fedora 19. The command can be as follows:
# Service mysqld stop
Then properly extract the data from the content in the default location/var/lib/mysql to the target location-for example, my,/home/mysql
Modify configuration file
My. cnf
First, modify the configuration file/etc/my. cnf. Datadir and socket. The meaning is self-evident, that is, to modify their paths. Of course, this my. cnf may appear elsewhere. If it is a new user, it may not be found, but it does not matter,
Ls/usr/share/mysql/
You can see some mysql-XXX-cnf. You can select some of them as the template, modify them, and drop/etc.
Get_mysql_option
In addition to cnf, you also need to modify the get_mysql_option setting...
Most of the files on the Internet are previous versions, and the file "/etc/rc. d/init. d/mysqld" should be modified. In fact, this script does not exist for fedora 19.
View the error message. The error prompt is as follows:
[Root @ f-argcv etc] # systemctl status mysqld. service
Mysqld. service-MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mysqld. service; enabled)
Active: failed (Result: exit-code) since Wed 19:38:22 HKT; 8 s ago
Process: 4936 ExecStartPost =/usr/libexec/mysqld-wait-ready $ MAINPID (code = exited, status = 1/FAILURE)
Process: 4935 ExecStart =/usr/bin/mysqld_safe -- basedir =/usr (code = exited, status = 0/SUCCESS)
Process: 4913 ExecStartPre =/usr/libexec/mysqld-prepare-db-dir % n (code = exited, status = 0/SUCCESS)
Oct 23 19:38:20 f-argcv systemd [1]: Starting MariaDB database server...
Oct 23 19:38:21 f-argcv mysqld_safe [4935]: 131023 19:38:21 mysqld_safe Logging to '/var/log/mysqld. log '.
Oct 23 19:38:21 f-argcv mysqld_safe [4935]: 131023 19:38:21 mysqld_safe Starting mysqld daemon with databases from/home/mysql/data
Oct 23 19:38:21 f-argcv mysqld_safe [4935]: 131023 19:38:21 mysqld_safe mysqld from pid file/var/run/mysqld. pid ended
Oct 23 19:38:22 f-argcv systemd [1]: mysqld. service: control process exited, code = exited status = 1
Oct 23 19:38:22 f-argcv systemd [1]: Failed to start MariaDB database server.
Oct 23 19:38:22 f-argcv systemd [1]: Unit mysqld. service entered failed state.
The source of the problem seems to be/usr/libexec/mysqld-wait-ready. Check and modify parameters such as basedir, and then run...
Other methods
Actually, there is still a final solution: Back up data, detach, and reinstall-yum is actually very convenient here.
Then configure the file, especially Modify/usr/bin/mysql_install_db, where the ldata Parameter
Mysql_install_db
You can.
Postscript
Later, I re-installed the machine and assigned a scalable partition to var. In my opinion, this is the most comfortable setting.
-------------------------------------- Split line --------------------------------------
MySQL data recovery experiment with mysqldump and mysqlbinlog
Install MySQL in Ubuntu 14.04
MySQL authoritative guide (original book version 2nd) Clear Chinese scan PDF
Ubuntu 14.04 LTS install LNMP Nginx \ PHP5 (PHP-FPM) \ MySQL
Build a MySQL Master/Slave server in Ubuntu 14.04
Build a highly available distributed MySQL cluster using Ubuntu 12.04 LTS
Install MySQL5.6 and Python-MySQLdb in the source code of Ubuntu 12.04
MySQL-5.5.38 universal binary Installation
-------------------------------------- Split line --------------------------------------
This article permanently updates the link address: