mysqldump:mysqldump -u root <DATABASE_NAME> <DUMP_FILE>.sql;To create the new database:
mysql
mysql> create database <NEW_DATABASE_NAME>;
mysql> use <NEW_DATABASE_NAME>;
mysql> source <DUMP_FILE>.sql;
This is a place where I record snippets of information that I've found useful and that I think that I may need to refer to again. If anyone else finds them useful as well then that's great.
mysqldump:mysqldump -u root <DATABASE_NAME> <DUMP_FILE>.sql;mysql
mysql> create database <NEW_DATABASE_NAME>;
mysql> use <NEW_DATABASE_NAME>;
mysql> source <DUMP_FILE>.sql;
mysqldump: Got error: 23: Out of resources when opening file './ref_ca/dsi_scenario_longs.MYD' (Errcode: 24) when using LOCK TABLES" when doing a mysqldump on Mac OSX.--single-transaction as mentioned at Out of resources for mysqldump - Server Fault.
Again this is taken directly from mysql.com
You need to login into mysql and run the following sql:
UPDATE mysql.user SET Password=PASSWORD("<NEW_PASSWORD>") where user="<USER_NAME>"
You have to connect to do this and easiest is to connect as the root user:
mysql --user=root
The documentation for this can be found mysql.com
The command to start mysql if the startup item is installed is:
sudo /Library/StartupItems/MySQLCOM/MySQLCOM start
Otherwise use:
/usr/local/mysql/bin/mysqld_safeand then bg to background the process.
Importing a mysql text dump is pretty staright forward:
mysql table_name < mysql_dump_file.sql
In addition the following options may be of use:
Put together this is used in the following way:
mysql --user=YOUR_USER_NAME -p -h localhost table_name < mysql_dump_file.sql
This is a simple script to back up a MySQL database by creating a text dump of all the tables. It is based on a script I found on the The PHP Cult.
#!/bin/bash user=USERNAME; password=PASSWORD; tmp=BACKUP_DIRECTORY; dblist=$tmp/dblist.txt mkdir $tmp /usr/bin/mysql -e "show databases" -u $user --password=$password | sed s/^Database//g | sed s/\|//g | sed s/\ //g > $dblist for i in `cat $dblist` do export FILENAME1="$i.sql" echo "Backing up $i to $FILENAME1 ...." /usr/bin/mysqldump -u $user --opt --password=$password $i > $tmp/$FILENAME1 done