MySQL Usage: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
To login as root: | |||
ssh root@clondb1 | |||
mysql -u root -p | mysql -u root -p | ||
To dump one database or several databases: | |||
mysqldump --opt db_name > /usr/local/clas/mysql_dump/backup-file.sql | mysqldump --opt db_name > /usr/local/clas/mysql_dump/backup-file.sql | ||
mysqldump --databases db_name1 [db_name2 ...] > /usr/local/clas/mysql_dump/my_databases.sql | mysqldump --databases db_name1 [db_name2 ...] > /usr/local/clas/mysql_dump/my_databases.sql | ||
To restore one database: | |||
mysql -u root -p db_name < /usr/local/clas/mysql_dump/backup-file.sql | mysql -u root -p db_name < /usr/local/clas/mysql_dump/backup-file.sql | ||
To restore all databases ('USE <db_name>' statement must be in the file): | |||
mysql -u root -p < /usr/local/clas/mysql_dump/backup-file.sql | mysql -u root -p < /usr/local/clas/mysql_dump/backup-file.sql | ||
To copy database from one server to another: | |||
mysqldump --opt db_name | mysql --host=remote_host -C db_name | mysqldump --opt db_name | mysql --host=remote_host -C db_name | ||
To dump all databases: | |||
mysqldump --all-databases > /usr/local/clas/mysql_dump/all_databases.sql | mysqldump --all-databases > /usr/local/clas/mysql_dump/all_databases.sql | ||
NOTE: there is a script '/database/dumpdb' (obtained from Bryan Hess and adjusted) which is running from cron job, | |||
it is dumping all databases from clondb1 to / | it is dumping all databases from clondb1 to /mysql/clondb1_dump/ directory on fileserver. See usage inside the script. | ||
directory on fileserver. See usage inside the script. | |||
To creating new table (example): | |||
create table clonalarm( | create table clonalarm( | ||
alarm_id integer not null, | alarm_id integer not null, | ||
alarm_status integer default NULL, | alarm_status integer default NULL, | ||
Line 37: | Line 37: | ||
alarm_text varchar(120) default NULL, | alarm_text varchar(120) default NULL, | ||
help_id integer default NULL | help_id integer default NULL | ||
)\g | )\g | ||
To import data from ASCII file into existing table use 'mysqlimport' (example): | |||
mysqlimport -u root -p clasprod ./clonalarm.txt | |||
where 'clasprod' is database name and 'clonalarm.txt' is file in /database directory. | where 'clasprod' is database name and 'clonalarm.txt' is file in /database directory. | ||
File name must coinside with table name ! | File name must coinside with table name ! | ||
To autorize 'clasrun' access from clon10.jlab.org to 'clas_online' database do following: | |||
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON clas_online.* TO clasrun@clon10.jlab.org; | |||
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON clas_online.* TO clasrun@clon10.jlab.org; | |||
Other example: | Other example: | ||
mysql> grant all on clas_online.* to clasrun@clon10.jlab.org identified by 'your_mysql_user_password'; | mysql> grant all on clas_online.* to clasrun@clon10.jlab.org identified by 'your_mysql_user_password'; | ||
To revoke access, do following: | To revoke access, do following: | ||
revoke all on clas_online.* from clasrun@clon10.jlab.org; | |||
For example if 'clasrun' want to assess 'test' database on 'clondb1' from remote host, it should use following commands: | For example if 'clasrun' want to assess 'test' database on 'clondb1' from remote host, it should use following commands: | ||
mysql -h clondb1 -u clasrun | mysql -h clondb1 -u clasrun | ||
mysql> use clasprod; | mysql> use clasprod; | ||
mysql> show tables; | mysql> show tables; | ||
mysql> describe clonalarm; | mysql> describe clonalarm; | ||
mysql> select * from clonalarm; | mysql> select * from clonalarm; | ||
mysql> quit | mysql> quit | ||
Revision as of 12:44, 10 January 2007
To login as root:
ssh root@clondb1 mysql -u root -p
To dump one database or several databases:
mysqldump --opt db_name > /usr/local/clas/mysql_dump/backup-file.sql mysqldump --databases db_name1 [db_name2 ...] > /usr/local/clas/mysql_dump/my_databases.sql
To restore one database:
mysql -u root -p db_name < /usr/local/clas/mysql_dump/backup-file.sql
To restore all databases ('USE <db_name>' statement must be in the file):
mysql -u root -p < /usr/local/clas/mysql_dump/backup-file.sql
To copy database from one server to another:
mysqldump --opt db_name | mysql --host=remote_host -C db_name
To dump all databases:
mysqldump --all-databases > /usr/local/clas/mysql_dump/all_databases.sql
NOTE: there is a script '/database/dumpdb' (obtained from Bryan Hess and adjusted) which is running from cron job, it is dumping all databases from clondb1 to /mysql/clondb1_dump/ directory on fileserver. See usage inside the script.
To creating new table (example):
create table clonalarm( alarm_id integer not null, alarm_status integer default NULL, alarm_time date default NULL, system char(20) default NULL, alarm_text varchar(120) default NULL, help_id integer default NULL )\g
To import data from ASCII file into existing table use 'mysqlimport' (example):
mysqlimport -u root -p clasprod ./clonalarm.txt
where 'clasprod' is database name and 'clonalarm.txt' is file in /database directory. File name must coinside with table name !
To autorize 'clasrun' access from clon10.jlab.org to 'clas_online' database do following:
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON clas_online.* TO clasrun@clon10.jlab.org;
Other example:
mysql> grant all on clas_online.* to clasrun@clon10.jlab.org identified by 'your_mysql_user_password';
To revoke access, do following:
revoke all on clas_online.* from clasrun@clon10.jlab.org;
For example if 'clasrun' want to assess 'test' database on 'clondb1' from remote host, it should use following commands:
mysql -h clondb1 -u clasrun mysql> use clasprod; mysql> show tables; mysql> describe clonalarm; mysql> select * from clonalarm; mysql> quit