Install MySQL Server 5 on Ubuntu
Installing MySQL 5 Server on Ubuntu is a quick and easy process. It almost feels like it should be more difficult.
Open a terminal window, and use the following command:
sudo apt-get install mysql-server
If you are running PHP you will also need to install the php module for mysql 5:
sudo apt-get install php5-mysql
To create a new database, use the mysqladmin command:
mysqladmin create <databasename>
See, really easy!

Daily Email Updates
You can get our how-to articles in your inbox each day for free. Just enter your name and email below:


mysqladmin: connect to server at ‘localhost’ failed
error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’
Check that mysqld is running and that the socket: ‘/var/run/mysqld/mysqld.sock’ exists!
The last step posted above does not work:
Here is the output:
honey@honey:~$ mysqladmin create test
mysqladmin: connect to server at ‘localhost’ failed
error: ‘Access denied for user ‘honey’@'localhost’ (using password: NO)’
This tutorial is great except like all the others trying to follow this tutorial gets the same exception/errors, this means you have forgotten some steps, how to start the server. Please update this tutorial and correct it.
The command for installing mysql-server-5.0 seems to work, but your instructions are lacking detail. For example, how do you start and stop the server and client? Furthermore, are environment variables required? Most computer users don’t want to hack and fuss with their machines for all eternity. I realize that a complete tutorial on mysql is out of the question. However, enough information should be provided so that mysql can be installed, configured, and tested. Additionally, you should provide instructions for those users that download the mysql archive directly to their desktop and wish to install it from their.
Start your MySQL server by using the command:
/etc/rc.d/init.d/mysql start
you can also stop it via the command:
/etc/rc.d/init.d/mysql stop
Surprisingly enough, a Google search for “mysql start” returned this in the first couple of results.
Previous example for Mysql start-stop don’t work for me. I using Ubuntu 7.10.
Good example for me is:
Start MySQL server by using the command:
sudo /etc/init.d/mysql start
Stop MySQL server by using the command:
sudo /etc/init.d/mysql stop
Sorry for my english…
A google search does indeed tell me that I should use the command:
/etc/rc.d/init.d/mysql start
However, as a newcomer to both MySQL and Ubuntu/Linux this doesn’t help me – I simply get the new error “bash: /etc/rc.d/init.d/mysql: No such file or directory”. Googling that error doesn’t help either; the top results seem to be people who have managed to edit their conf files and have made their installation *stop* working; I haven’t yet got as far as making it work in the first place.
I have installed the MySQL client and server through Synaptic, but haven’t yet managed to work out how to start the server. I’m afraid I have to agree with the previous comments on this article – there simply isn’t enough information to enable a newbie to work out how to begin. If you’re not a newbie, you probably don’t need this article at all. More details here would be wonderful!
(And comments like “see, really easy!” don’t help newbies’ frustration levels – I know that what I want to do is simple; I know the rest of the world finds it easy; but knowing that it’s simple doesn’t help me work out what on earth it is I need to type/edit/install/mess about with to make this work).
i try this
sudo apt-get install mysql-server
but dont work
NOT FOUND
When I do this I get this error:
conorkirk@Conor-WebServer:~$ sudo mysqladmin create conor_data
mysqladmin: connect to server at ‘localhost’ failed
error: ‘Access denied for user ‘root’@'localhost’ (using password: NO)’
conorkirk@Conor-WebServer:~$
The tutorial didn’t say how to set up Mysql users.
apt-get worked fine for me. Just pick a password for root.
Startup & shutdown: System Menu -> Administration -> Services
You control mysql from here.
You can do ‘ps ax | grep mysql’ in a terminal window to see if it is running (you should see /usr/sbin/mysqld running).
Install MySQL Administrator from Add/Remove to create & manage databases with a nice GUI.
Very helpful. I’m working in Ubuntu 8.04 and it went well for me. Thanks for the tutorial!
mysqladmin -u root -p create
and enter the root paaword you set in the installation of mysql
And if you need to connect to MySQL remotely comment out the line:
bind-address = 127.0.0.1
in your /etc/mysql/my.cnf file, followed by a restart.
ab_iron
I installed mysql on Ubuntu (whatever the latest version is) and tried to migrate some databases from my mac. Big mistake. Now mysql is screwed completely, won’t start. I can uninstall it, I can reinstall it, but it will not start. None of the suggestions on this page make any difference.
root@nelson:~# /etc/init.d/mysql start
* Starting MySQL database server mysqld
…done.
/usr/bin/mysqladmin: connect to server at ‘localhost’ failed
error: ‘Access denied for user ‘debian-sys-maint’@'localhost’ (using password: YES)’
root@nelson:~# mysqladmin -u root -p create
Enter password:
mysqladmin: connect to server at ‘localhost’ failed
error: ‘Access denied for user ‘root’@'localhost’ (using password: YES)’
I’m completely hosed. Apparently I can’t even wipe it and start over. Any ideas?
I had the same problems then you guys have already mention but we fergot something very simple, i had installed the client end of the mysql, but i had not installed the mysql SERVER 5.5, so i could not connected to the server even after tapying the password, because it was not installed, ahh, so we need to install the
sudo apt-get install mysql-server 5.0
sudo apt-get install mysql-Client 5.0
Trevor: Take a look at http://dev.mysql.com/doc/refma.....sions.html , it details how to reset the root password.
I installed Ubuntu then mysql from the packages option. After installation I access mysqladministrator and mysql queries from the applications tab. When I select either, I am required by the mssql administrator GUI to enter a host name, password and userID. I tried the local host (127.0.0.1)and the network host (127.0.1.1) with no luck. Any ideas?
It was easy to install. But now I can’t find it on my computer. It’s not on my Applications tab. When I look in Add/Remove Applications, it is not listed. I need to start it so I can peruse the help files, since I’m a total novice. I just want mysql so that I can install and practice using drupal…
oh, thank you for this posted, i very like ubuntu and i fell interested with this tutorial and with comments of visitor blog !
Thank !
not bad but little corrections
“/usr/bin/mysqladmin: connect to server at ‘localhost’ failed”
you must switch to user /no root /
type:
su user
sudo /etc/init.d/mysql start
type password for user
sudo mysqladmin -u root -p create mydatabase
I don’t understand why all of you have such problem (with starting of mysql).
I using ubuntu 8.1 and after downloading the mysql just entered > mysql and all work fine. The mysql well started and you able to launch any commands (like CREATE TABLE or SHOW DATABASES)
I had same problem with mysql not starting automatically. Install works fine and can run mysql without problems. When I reboot the PC I get the message
“/usr/bin/mysqladmin: connect to server at ‘localhost’ failed”
Using the advice above to
you must switch to user /no root /
type:
su user
sudo /etc/init.d/mysql start
type password for user
It now works fine. I just need to get this to run on startup
If you are using Ubuntu Hardy Heron try using:
/usr/bin/mysql_setpermission to set the database user permissions. It is very simple and straight forward.
In order to get mysql to start when the system start you need to place a link from /etc/init.d/mysql in the appropriate rc.d directory. Since you are looking for mysql to start in the gnome environment you will want to set the link in the /etc/rc5.d directory.
I have found that leaving the root password blank on your local system helps with development.
Thanks. Works great!
Thanks
Its helping a lot to implement things, keep it up.
Thanks Geek Boy !!
any ideas for MySQL WorkBench ?
any tips on improving performance for a dedicated ubuntu mysql server?
Hi all,
Thanks for all the tips. But I am encountering a prob from few days. Whenever I try to install something, it starts to install nicely but later the below command appears on terminal
Setting up acidlab (0.9.6b20-22) …
This command remains as it is. Even though one day I left comp on for 8 hours or so allowing terminal to set acidlab but it didn’t. Now I was installing mysql everthing went rite It also prompted me to enter password for root. (But as mike as commented I didn’t enter any password) after that this line appeared on terminal Setting up acidlab (0.9.6b20-22) …
and terminal is not progressing at all. So please help me (As I need to submit my DBMS project)
To Create Mysql user
mysql_install_db
mysqladmin -u root password YOURPASS
mysql -u root -p
Password: YOUR PASS
mysql>create database DBNAME;
mysql>\q
TO import
mysql torrentflux < omggggg.sql -u root -p
Password: YOUR PASS
Thanks
You need to be an admin in order to do some of these things. Try adding yourself to the sudoers file (terminal>visudo). Also, if you have problems, lifehacker is a great place to get tips on mysql as well.
hi
nice i use web server as well as ubuntu 1st time
nice info
keep it up , yaar
warm wish
aditya g jadhav
I got around the connection problem by typing ‘root’ (without quotes) as username instead of the username I am logged on as.
for mi on Ubunt 9.04 worked ok:
sudo apt-get install mysql-server
sudo /etc/init.d/mysql start
mysqladmin -u root -p create mydatabase
not working on Ubuntu 9.10 Beta