How to Backup and Restore a MySQL Database Using mysqldump

How to Backup a MySQL Database With mysqldump

mysqldump -u userNameWithPrivileges -p databaseName > outputFileName.sql

How to Restore a mysqldump Backup

mysql -u userNameWithPrivileges -p database < outputFileName.sql

* Replace “userNameWithPrivileges” with the username of a MySQL account that can read/write to the database being backed up / restored.

MySQL logo

Error When Compiling PHP in CentOS 64 Bit

Library files in CentOS 64 bit are stored in the directory /usr/lib64. But in normal 32 bit CentOS, library files are stored in /usr/lib so this causes a problem when trying to compile source code that looks for library files in /usr/lib. When using the default configure options for compiling PHP, the directory /usr/lib is searched for library files so if you have any 64 bit applications installed, their associated library files will not be found. For example, trying to compile PHP with the configure option:

--with-mysql=/usr

will result in the error:

/usr/bin/ld: cannot find -lmysqlclient

You can fix this MySQL error and other configure errors relating to library files not being found by adding the following option to the configure line:

--with-libdir=lib64

Code

MySQL – How to Create an Admin User Account

If you want to create an additional admin account for MySQL server, connect to the MySQL server with a MySQL client program and execute the following command:

GRANT ALL ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

Change the word “admin” to whatever username you want to use for the admin account and change “password” to whatever password you want to use for that account.

The above SQL command creates an admin account that can only connect from the server which is running the MySQL database service. If you want to allow the admin account to log in from any IP address then replace “localhost” with “%”. The “%” acts as a wild card character.

GRANT ALL ON *.* TO 'admin'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;

If you want to only allow the admin account to log in from a specific IP or range of IPs then use the wildcard character:

GRANT ALL ON *.* TO 'admin'@'192.168.1.%' IDENTIFIED BY 'password' WITH GRANT OPTION;

The above example allows the admin account to log in from any IP address that starts with 192.168.1.

MySQL logo