Friday, July 18, 2008

Starting with MySQL

All the beginning are terrible and slow... again and again looking into the manual for the same commands.

Install
apt-get install mysql-client mysql-server mysql-common php5-mysql

Set root password
mysqladmin password 'new_root_password'

Login to DB
mysql -u root -p

Create database
CREATE DATABASE db_name;

Create regular user and grant appropriate rights
SELECT PASSWORD('secret_password');
CREATE USER user_name IDENTIFIED BY 'secret_password';
GRANT ALL ON db_name.* TO 'user_name'@'host_name' IDENTIFIED BY 'secret_password';
^D

Login under the regular user
mysql -u user_name -p db_name

Create table
DROP TABLE IF EXISTS users;
CREATE TABLE users (
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
created_date DATETIME,
name VARCHAR(200),
phone VARCHAR(200)
);

Create index
CREATE INDEX index_users_name ON users (name);
details

No comments: