How do I install Oracle (Sun) MySQL database server v5.x under Ubuntu Linux operating systems? How do I add a new user and database for Apache web server and php access under Ubuntu Linux?
MySQL database server is now owned by Oracle (formally Sun Microsystems) but can be installed using command line options without compiling anything under Ubuntu Linux. Open a terminal and type the following commands to upgrade package database:
$ sudo apt-get update
$ sudo apt-get upgrade
Install MySQL Server
Type the following command to install latest stable MySQL server software:
$ sudo apt-get install mysql-server mysql-common mysql-client
You will be prompted to setup mysql root user account password. You can install php access module as follows:
$ sudo apt-get install php5-mysql
$ sudo /etc/init.d/apache2 restart
A Perl5 database interface to the MySQL data can be installed as follows:
$ sudo apt-get install libdbd-mysql-perl
How Do I Access MySQL Server?
Type the following command:
$ mysql -u root -p
You need to supply root user account password:
Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 107 Server version: 5.1.41-3ubuntu12.3 (Ubuntu) Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
Task: List Your Databases
Type the following sql command at mysql> prompt:
mysql> show databases;
Sample outputs:
+--------------------+ | Database | +--------------------+ | information_schema | | mysql | | wiki | | wikidb | | wpmu | +--------------------+ 5 rows in set (0.02 sec) mysql>
Task: Add A New Database
To add a new database called myapps, enter:
mysql> create database myapps;
Sample outputs:
Query OK, 1 row affected (0.00 sec)
Task: Add A New User For myapps Database
Add a user called vivek and grant access from localhost:
mysql> GRANT ALL ON myapps.* TO vivek@localhost IDENTIFIED BY 'Add-Your-Password-Here';
Task: Add A New User For myapps Database (Network Access)
Make sure user vivek can access myapps database from Apache web server installed at 192.168.1.10:
mysql> GRANT ALL ON myapps.* TO vivek@192.168.1.10 IDENTIFIED BY 'Your-Password-Here';
How Do I View Log Files?
The log is stored at /var/log/mysql/error.log, enter:
$ tail -f /var/log/mysql/error.log
$ grep 'something' /var/log/mysql/error.log
Configure MySQL Server
The default configuration file is located at /etc/mysql/my.cnf, enter:
$ sudo vi /etc/mysql/my.cnf
Change network binding to 192.168.1.5 so that web server located at 192.168.1.10 can access database:
bind-address = 192.168.1.5
Save and close the file.
How Do I Start / Stop / Restart Server?
Type the following commands:
$ sudo service mysql restart
$ sudo service mysql stop
$ sudo service mysql start
Sample outputs:
mysql start/running, process 4930
You can also use the following command for older version:
$ sudo /etc/init.d/mysql start
$ sudo /etc/init.d/mysql stop
$ sudo /etc/init.d/mysql restart
See Also:
- Shell Script To Add MySQL Database, Username and Password Including Remote Host Access
- Ubuntu / Debian Linux: Services Configuration Tool to Start / Stop System Services
- Mysql user creation – setting up a MySQL new user account
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- My 10 UNIX Command Line Mistakes
- Linux: 20 Iptables Examples For New SysAdmins

- 25 PHP Security Best Practices For Sys Admins
- The Novice Guide To Buying A Linux Laptop
- 10 Greatest Open Source Software Of 2009
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
Facebook it - Tweet it - Print it -

