CREATE DATABASE database;
mysqladmin create is a command-line wrapper for this function.
NB: in MySQL,
CREATE SCHEMA is a perfect synonym of
CREATE DATABASE, contrarily to some other DBMS like Oracle or SQL Server.
DROP DATABASE database;
Require ? privilege.
mysqladmin drop is a command-line wrapper for this function. The
-f option can be used to suppress the interactive confirmation (useful for unattended scripts).
In some 5.1.x versions there was a
RENAME DATABASE db1 TO db2; command, but it has been removed because renaming databases via SQL caused some data loss problems.
However, in the command-line, you can create/export/import/delete:
mysqladmin create name2 mysqldump --opt name1 | mysql name2 mysqladmin drop -f name1
Another option, if you have root access, is to rename the database directory:
cd /var/lib/mysql/ /etc/init.d/mysql stop mv name1/ name2/ /etc/init.d/mysql start
You also need to drop privileges on name1 and recreate them on name2:
UPDATE mysql.db SET `Db`='name2' WHERE `Db`='name1'; FLUSH PRIVILEGES;
There is no direct copy command in MySQL. However, this can easily be done using some tools.
The mysqldump command-line can be used to generate a complete flat-file copy of the database. You can then reinject this copy in another database.
This requires a direct access to the database; if you do not have it, you may need to use phpMyAdmin instead.
# First, clean-up the target database: mysqladmin drop -f base2 mysqladmin create base2 # Copy base1 to base2: mysqldump --opt base1 | mysql base2
To set an automatic backup every day at midnight, in Linux:
$ crontab -e 0 0 * * * /usr/local/bin/mysqldump -uLOGIN -PPORT -hHOST -pPASS base1 | gzip -c > `date "+\%Y-\%m-\%d"`.gz
mysql -h localhost -u root MaBase < MaBase.sql
"C:\Program Files (x86)\EasyPHP\binaries\mysql\bin\mysql.exe" -h localhost -u root MyDB < MyDB.sql
Contrarily to the PhpMyAdmin importations, there is no limit. For example, we can load a 2 GB database in five minutes.
| This section is a stub.
You can help Study Guides by .
Tools: MySQL Migration Toolkit
DBDesigner begins to be old. It is released under the GNU GPL, but it cannot be fully considered as free software since it requires the non-free Kylix compiler to build.
Meanwhile, if you use the latest release of DBDesigner, you'll find that it cannot connect to MySQL, with the "unable to load libmysqlclient.so" error. To workaround this,
sudo ln -sf /usr/lib/libmysqlclient.so.10 /usr/lib/DBDesigner4/libmysqlclient.so
xorg-x11-libs-6.8.2-37.FC220.127.116.11.i386.rpmfrom FC4) and extract it:
rpm2cpio x.rpm | cpio -i
sudo cp libXft.so.1.1 /usr/lib ldconfig
You now can connect to your MySQL5 server from DBDesigner4. Consider this a temporary work-around waiting for community (free) and commercial (not free) versions MySQL Workbench.
Typical configuration :
It's a client configuration : we need
aptitude install mysql-client
yum install mysql
Before installing ODBC, we can test the remote connexion locally:
$ mysql -h mysqlhost -u user1 mysqldatabase -p Enter password: PassUser1
You must have create the database
mysqldatabase and the user
It seems there is no problem (hope there is not ;-)):
Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 33 to server version: 5.0.24a-Debian_5~bpo.1-log Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql>
Then, it's possible to test, through different queries :
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysqldatabase | +--------------------+ 2 rows in set (0.00 sec) .... mysql> quit; Bye
Fine ! Let's go with OOo and ODBC, on the client machine:
aptitude install libmyodbc unixodbc
yum install mysql-connector-odbc unixODBC
/etc/odbc.ini (empty file) and
/etc/odbcinst.ini are created.
odbcinst.ini declares the available ODBC driver. Here's the MySQL statement (paths to the .so files may vary depending on the distribution); for Debian:
[MySQL] Description = MySQL driver Driver = /usr/lib/odbc/libmyodbc.so Setup = /usr/lib/odbc/libodbcmyS.so CPTimeout = CPReuse = FileUsage = 1
[MySQL] Description = ODBC for MySQL Driver = /usr/lib/libmyodbc3.so Setup = /usr/lib/libodbcmyS.so FileUsage = 1
Now we can use
# odbcinst -j unixODBC 2.2.4 DRIVERS............: /etc/odbcinst.ini SYSTEM DATA SOURCES: /etc/odbc.ini USER DATA SOURCES..: /root/.odbc.ini
For further options :
First of all, we have to create at least one DSN (Data Source Name or Data Set Name), because every ODBC connection is initialized through an existing DSN. It's true in every cases, so it is required for an ODBC connection from OOo.
To create a DSN, one have different possibilities :
unixODBC-kde). Finally, these graphical applications modify /etc/odbc.ini or ~/.odbc.ini
For instance, a
/etc/odbc.ini file (the name of the DSN is between brackets ):
[MySQL-test] Description = MySQL ODBC Database TraceFile = stderr Driver = MySQL SERVER = mysqlhost USER = user1 PASSWORD = DATABASE = mysqldatabase
In that case, the DSN is called MySQL-test
Then we can test, using isql command:
$ isql -v MySQL-test user1 PassUser1 +---------------------------------------+ | Connected! | | | | sql-statement | | help [tablename] | | quit | | | +---------------------------------------+ SQL> show databases; +-------------------+ | Database | +-------------------+ | information_schema| | mysqldatabase | +-------------------+ 2 rows affected 2 rows returned SQL> quit;
And now, from OOo:
-> File -> New -> Database -> Connecting to an existing database -> MySQL -> Next -> Connect using ODBC -> Next -> Choosing a Data Source -> MySQL-test -> Next -> Username : user1 (tick password required) -> Yes, register the database for me -> Finish
At that step, one is connected to the mysqldatabase database, under the user user1. Just before accessing the database, for example to create tables, one will give user1 password. Then, through OOo, it is now quite easy to access and manipulate the database. We can just notice that Java is required in the following cases :
GNU/Linux distros usually ships OpenOffice with IcedTea (
java-1.6.0-openjdk) or GCJ (
java-1.4.2-gcj-compat) so that these Java-based features work.
Manage research, learning and skills at defaultlogic.com. Create an account using LinkedIn to manage and organize your omni-channel knowledge. defaultlogic.com is like a shopping cart for information -- helping you to save, discuss and share.