sed -i 's/OLDDATABASENAME/NEWDBNAME/g' mysqldumpFile.sql
Then run:
mysql -p create NEWDBNAME; use NEWDBNAME; SOURCE /path/to/sql/fileNo need for a semicolon on the last line. Then check the success by:
show tables;
Websites and SEO
sed -i 's/OLDDATABASENAME/NEWDBNAME/g' mysqldumpFile.sql
Then run:
mysql -p create NEWDBNAME; use NEWDBNAME; SOURCE /path/to/sql/fileNo need for a semicolon on the last line. Then check the success by:
show tables;
mysql -u root -pThis logs you in as the root user (-u signifying which user you want to log in as) and -p signifies that you are logging in with a password, which you will be prompted for after you enter the command. The MySQL root password is set when you install MySQL server.
create database [nameOfDatabase];Don’t forget the ; at the end, or you’ll end up on a new line consisting of a > prompt waiting for more input. You can put the ; in then if you forgot to complete the command. An example of the above would be:
create database wikiDB;…which would create the database named wikiDB. You should see the following on a successful command:
Query OK, 1 row affected (0.04 sec)If that is all you had to do you can now exit MySQL by typing:
exit…and you’re done!
mysqladmin -u root -p password NEWPASSWORDEnter the current root password when prompted and replace NEWPASSWORD with the desired password. This should return you to the command prompt, and you can test whether it was successful by logging in:
mysql -u root -p
mysql -u root -pLog in using your root password. Next, list your databases:
show databases;On our test system this shows all of our databases like so:
mysql> show databases; +——————–+ | Database +——————–+ | information_schema | mysql | performance_schema | press | test | wiki +——————–+ 6 rows in set (0.10 sec)Select your wiki’s database:
USE wiki;Replace “wiki” in the above with your own database’s name.
UPDATE user SET user_password = MD5(CONCAT(user_id, ‘-‘, MD5(‘newpasswordgoeshere’))) WHERE user_name = ‘usernameofuser’;If this is successful you should get the following:
Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0If something has gone wrong (e.g. a non-existent username) you will get the following instead:
Query OK, 0 rows affected (0.03 sec) Rows matched: 0 Changed: 0 Warnings: 0All done! To leave mysql just type “exit”.
mysqldump -u root -p –all-databases > databasesBackup.sqlNote the two hyphens before “all”. This command creates the file databasesBackup.sql which contains the contents of all of your databases. This file can be easily rsync’d or scp’d elsewhere to create an offsite backup of your site’s databases.