Thursday, 19 May 2011

Installing MySQL

MySQL should be one of the first servers to be installed as you will rely on it for FTP, WWW and, if you go even further, Email. This is going to be easy.

Let's begin!

1. Install
yum install mysql mysql-server
(This is how you install it on CentOS. For other distributions you will use a similar software like apt-get and the packages may be named slightly different)

2. Load at startup / start
/sbin/chkconfig --levels 235 mysqld on
/etc/init.d/mysqld start

3. Test your installation
The usual way to connect is mysql -u myUsername -p, and you will be asked for a password. Simply mysql will assume user to be root and password to be empty. If the mysql command worked you are logged in and you should go to step 4.

4. Create a MySQL User
mysql> GRANT ALL PRIVILEGES ON *.* TO 'sys'@'localhost' IDENTIFIED BY 'secret'  WITH GRANT OPTION;

(This creates a user with full privileges on all databases)

5. Change (root) password (whenever you feel like doing this)
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newSecret');

6. Check and remove MySQL users
By default, the server comes with many users already active. All passwords are empty, You should remove most of them or at least change their passwords. I only leave root@localhost and I change it's password.
mysql> SELECT User, Host, Password FROM mysql.user;
mysql> DROP USER ''@'CentOS-56-64-minimal';
(Your users may look different)
mysql> quit

7. Test your new user
(this shouldn't work anymore)
mysql -u sys -p
(this should work)

That's it!

In order yo use MySQL you should learn how to create, import, backup a database and other simple things. Also, you might want to connect remote. I will cover all these in a different post.

No comments:

Post a Comment