apricoti

 

MysqlRecipeBook

Page history last edited by jonathan 1 yr ago

MySQL

 

Generate SQL statements to create a copy of a specific database (for making a sample etc)

 

mysqldump $dbname > $dbname.sql

 

Create the new database using above SQL statements

 

mysql -e "create database $dbname"

mysql $dbname < $dbname.sql

 

Add another database user to mysql permission tables

 

mysql mysql -e "INSERT INTO user SET Host='localhost',User='$dbuser',Password=password('$dbpasswd');"

mysql mysql -e "INSERT INTO db SET Host='localhost',Db='$dbname',User='$dbuser',Select_priv='Y',Insert_priv='Y',Update_priv='Y',Delete_priv='Y';"

mysqladmin reload

 

Another way to do this:

 

mysql -e "GRANT DELETE,INSERT,SELECT,UPDATE ON $dbname.* TO '$dbuser'@'localhost' IDENTIFIED BY '$dbpasswd';"

 

By the way, "localhost" in the above statements should match the FIRST entry for 127.0.0.1 in /etc/hosts. So if you have an entry like "127.0.0.1 localhost.localdomain" then you should use that instead, or change your hosts file to have "localhost" as the first entry for 127.0.0.1. You can test this using the -h parameter to mysql:

 

mysql $dbname -u $dbuser -p -h localhost

mysql $dbname -u $dbuser -p -h localhost.localdomain

mysql $dbname -u $dbuser -p -h 127.0.0.1

Comments (0)

You don't have permission to comment on this page.