Suppose you want to install and run MySQL on Ubuntu, run the following commands to install the MySQL in the terminal:
> sudo apt-get install mysql-server
> sudo apt-get install mysql-client
During the installation of the mysql-server, the user will prompted to enter the password for the root user account. After the installation is completed, the user can run the following command to find out whether mysql-server is running on the computer:
> sudo netstat -tap | grep mysql
To start, stop or restart mysql, run one of the following commands:
> sudo /etc/init.d/mysql start
> sudo /etc/init.d/mysql stop
> sudo /etc/init.d/mysql restart
To log into mysql, run the following command
> sudo mysql -u [username] -p
Enter the password in the prompt and press ENTER. For example, to log into the root user account:
> mysql -u root -p
After logging into mysql, first select the database by running the following sql command (which select the database "mysql" which is the default):
> use mysql;
To list the tables in the "mysql" database, run the following sql command:
> show tables;
Now suppose we want to take a look at what is inside the "user" datatable. Run the following sql command:
> select * from user;
To create and select a new database, e.g., "mylog", run the following sql command:
> create database mylog;
> use mylog;
To create a datatable, e.g., "mylogtable", in the database "mylog", run the following sql commands:
> use mylog;
> create table mylogtable(
id INT NOT NULL AUTO_INCREMENT,
country VARCHAR(255) NULL);
To exit mysql, run the following sql command:
> quit;
No comments:
Post a Comment