The previous article on the LAMP Server enables you to get started but you will need to do some configuration with MySQL before you go to far. This article and the next several articles will help you create a database and learn how to monitor it as well as backup and restore.
The MySQL server provides the database that will be connected with PHP and Apache. Installation is easily done with apt-get.
sudo apt-get install mysql-server
During the process you will be asked to create a password for the root user for MySQL. Note this is not the root user for the Linux system and the accounts should have different passwords. Be sure to write down the password. When the installation program completes, you can use the netstat utility to verify that MySQL is running correctly:
sudo netstat -tap | grep mysql
tcp 0 0 localhost:mysql *:* LISTEN 844/mysqld
Here, you can see that MySQL is active, and is listening on port 844.
Note that you don’t have to use the “sudo” command with MySQL server, even though we’re logged on with the user account instead of the root account.
You can add a password to both the server account and the mysql root account at the same time if for some reason your MySQL server did not get a password set.
mysqladmin -h localhost -u root password “the_password_you_want”
Now, if you try to log on to MySQL without the password, you’ll get this:
mysql -u root
ERROR 1045 (28000): Access denied for user ‘root’@'localhost’ (using password: NO)
So, to log on now, you’ll need to add a “-p” in the command-line. (The “-p” just means that you’ll be supplying the MySQL password.)
mysql -p -u root
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql> quit
Bye
There may also be some anonymous user accounts installed that don’t have passwords. For best security, you’ll want to get rid of them.
mysql -p -u root
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16 to server version: 5.0.22-Debian_0ubuntu6.06.2-log
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> delete from user where User = ”;
Query OK, 0 rows affected (0.03 sec)
mysql> delete from db where User = ”;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql>quit
Bye
Also for security’s sake, you’ll want MySQL to run with a non-privileged user account, instead of as root. For that, you can use the user and group named “mysql”. As luck would have it, the Ubuntu Server installation of MySQL has already taken care of this for you. (Of course, you would still log on to MySQL as “root” instead of as “mysql”.)
There is one other thing you might want to do, though, to keep the riff-raff out of your data directory. That is, take away the “group” and “other” permissions.
sudo chmod -R go-rwx /var/lib/mysql
If you are interested in a Live Course for Ubuntu 9.10 we provide that option as well. Otherwise, we hope you find this Free mini-course useful which we will roll out over a number of days..
{ 1 comment }
How about XAMPP? have any ide?
{ 2 trackbacks }