Connecting to the MySQL Server for the first time and setting a root password

The MySQL client program, has the following command format.

%>mysql [options] [database]

where [options] can be a series of options, and [database] is the name of the database we wish to use. Both are optional parameters. A useful command for first time users is:

%>mysql --help

To start, type the following command.

%>mysql -u root

Here were defined that we would like to log in with the username root (-u root). Something like the following should appear:

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 78 to server version: 5.0.22-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

Creating root password

Now you need to create a password for this account

mysql>SET PASSWORD FOR 'root'@'localhost' = PASSWORD('my_password');

root is the username
localhost is the hostname

To update your password

%>mysqladmin -u root password 'my_password'

running without privileges

sudo /etc/init.d/mysql stop
sudo mysqld --skip-grant-tables