Sunday, August 14, 2011

Getting started with mysql on linux

Getting started with MySQL is really easy. First you want to install the mysql server. Then you can start the server with this command:

Code:

sudo /etc/init.d/mysql start

Then, because intially the root user has no password, we want to set the password like this:

Code:

mysqladmin -u root password myPassword

You can now login to the mysql server with this:

Code:

mysql -u root -p

You'll need to type in the password that you entered earlier.

Every new MySQL install has 2 databases: mysql and test. Do NOT screw up your mysql database because here is where all the permission and user info is. The test DB is for you to play around with.The MySQL documentation is excellent. You'll probably want to set up a new user next. The MySQL docs can help you there.
Source: http://ubuntuforums.org/showthread.php?t=13245


Error:
#mysqladmin -u root password root123

mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
ANS:
This error normally comes when you have already set the root password and forgot it. So just change the root password by following method:
1. Stop the MySQL Server.

sudo /etc/init.d/mysql stop


2. Start the mysqld configuration.

sudo mysqld --skip-grant-tables &


3. Open a new tab and
Login to MySQL as root.

mysql -u root mysql


4. Replace YOURNEWPASSWORD with your new password!

UPDATE user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root'; FLUSH PRIVILEGES; exit;
5. Now stop the mysqld by pressing Ctr + C and start mysql by following command
/etc/init.d/mysql start


6. login to the mysql server with this new Password:
mysql -u root -p
Enter Password.


Note: This method is not regarded as the securest way of resetting the password. However it works.


References

MySQL 5.0 Reference Manual: How to Reset the Root Password

No comments:

Post a Comment