
My SQL Administration
Introduction
This is a simple guide to mySQL administration using the command line client. Generally mySQL administration is not a difficult task especially with the different administration tools out there, not least phpMyadmin.
Connecting to mySQL
To connect using the command line client you need to open a command line or a shell prompt. Then simply type:
mysqlThis is the most simple way to connect you to your mySQL server. Of course it is too simple for a lot of mySQL servers installations because we haven't specified any connection details. Connection details most commonly are the hostname and suitable security credentials such as user name and password.
This is a more useful and more likely mySQL command line syntax
mysql -uroot -ps3cr3tpassw0rd -hlocalhostThis will tell the mysql client to use the username of root to use the password of s3cr3tpassw0rd and to connect to the computer name of localhost
Assuming these details are correct you should see a prompt that looks something like this.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 319
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>Once you see this you are connected and ready to begin administering your system.
Creation of databases
To begin working on mySQL you need to create a database. This is a straight forward command.
CREATE DATABASE <databasename> ;For example if you wanted to create a database called "mystuff" you would use this command.
CREATE DATABASE mystuff ;If the database already exists you will be notified of this
#1007 - Can't create database 'mystuff'; database exists.if you want to avoid this error message, instead type
CREATE DATABASE IF NOT EXISTS mystuff;Now you have created the database you are ready to begin working on it. So you need to tell mySQL that this is the database you wish to connect to. This is accomplished with the "USE" command.
use mystuff;