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
php
$ sudo apt-get upgrade
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
html
Type the following command:
$ mysql -u root -p
You need to supply root user account password: mysql
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>
Type the following sql command at mysql> prompt:
mysql> show databases;
Sample outputs: linux
+--------------------+ | Database | +--------------------+ | information_schema | | mysql | | wiki | | wikidb | | wpmu | +--------------------+ 5 rows in set (0.02 sec) mysql>
To add a new database called myapps, enter:
mysql> create database myapps;
Sample outputs: web
Query OK, 1 row affected (0.00 sec)
Add a user called vivek and grant access from localhost:
mysql> GRANT ALL ON myapps.* TO vivek@localhost IDENTIFIED BY 'Add-Your-Password-Here';
sql
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';
apache
The log is stored at /var/log/mysql/error.log, enter:
$ tail -f /var/log/mysql/error.log
ubuntu
$ grep 'something' /var/log/mysql/error.log
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. app
Type the following commands:
$ sudo service mysql restart
$ sudo service mysql stop
$ sudo service mysql start
Sample outputs: spa
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