Want to take part in these discussions? Sign in if you have an account, or apply for one below
_____________________
Create mysql user and group
Create temporary and data directory
Initiate database
Setting permissions
Copy default config file
Edit the configuration file and change the socket path for both client and server section.
Setting init script
Set the path of my.cnf file in init script
Start Mysql
mysqldump --all-databases -u root -p > mysql.sql
Important: In Mysql 5 you may get this error "Got error: 1044: Access denied for user 'root'@'localhost' to database 'information_schema' when using LOCK TABLES". In this case use below command for mysql 5.
mysqldump --single-transaction --all-databases -u root -p > mysql.sql
IF you need to restore that backup to an old version of mysql then use below switch
--compatible=mysql40
or
--compatible=mysql323
Suppose you have a 100 GB mysql dump file mysql.sql.
First execute this command to get the line numbers of all "CREATE DATABASE " statements.
grep -n "CREATE DATABASE" mysql.sql
Output will be like...
113968:CREATE DATABASE /*!32312 IF NOT EXISTS*/ `MyDatabase1`;
209784:CREATE DATABASE /*!32312 IF NOT EXISTS*/ `MyDatabase2`;
904563::CREATE DATABASE /*!32312 IF NOT EXISTS*/ `MyDatabase3`;
We want to extract backup of MyDatabase2, It starts from line 209784 and goes up to line 904563. We can get that data by using below command.
csplit -k mysql.sql 209784 904563
This command will create 3 files with names like XX00,XX01,XX02. XX00 will have data from line 1 to 209784, XX02 will have data from line 209784 to 904563. And XX03 will have data from line 904563 to the end of file.
So XX01 is the backup we require and it can be restored with mysql command line.
-Stop the mysql
-Now start it with --skip-grant-tables
/usr/bin/mysqld_safe --skip-grant-tables &
-Now ...
mysql --user=root mysql
Press enter when it prompt for password. And after login run this ..
update user set Password=PASSWORD('new-password-here') WHERE User='root';
-Kill mysql and start it again with your usual start script (e.g /etc/init.d/mysql start).
1 to 1 of 1