MySQL on Ubuntu 9.10 with JDBC support


Install MySQL

libmysql-java is only needed for JDBC support
sudo apt-get install mysql-server mysql-client libmysql-java

Set the root password. If this gives you an error (likely), then reset the root password according to the next section.
mysqladmin -u root password pw
mysql -u root -p

Reset the root password

Note that anyone with sudo access to your system can reset the root password.

sudo /etc/init.d/mysql stop
sudo /usr/bin/mysqld_safe --skip-grant-tables &
sudo mysql -u root mysql

mysql> UPDATE user SET Password=PASSWORD('new_pw') WHERE User='root';
mysql> exit

sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

Set the classpath for JDBC

This will set the classpath for all users on the system
sudo gedit /etc/environment

Add the following line
Log out and back in

Basic Usage

Log into mysql as root
mysql -u root -p

Create a new user with a password
mysql> CREATE 'User' user_name IDENTIFIED BY 'pw';

Create a new database
mysql> CREATE database db_name;

Grant a user privileges to access a database
mysql GRANT ALL PRIVILEGES ON db_name TO user_name@localhost IDENTIFIED by "pw";

Log in as a user
mysql -u user_name -p

Log in as a user on localhost
mysql -u user_name -h -p