The general installation of software in Ubuntu only requires a few commands, installation of MySQL is also, the following steps:
1, in order to get the latest installation package, first update the list of packages
sudo apt-get update
2. Install MySQL server
sudo apt-get install Mysql-server
Appear as: Set the password, and then re-enter the password, OK.
3. Install the MySQL client
sudo apt-get install mysql-client
4. Install MySQL Library
sudo apt-get install Libmysqlclient-dev
5. Check whether the installation is successful
sudo netstat-tap | grep MySQL
Appears as: MySQL socket in Listen state indicates successful installation.
6. Log in to MySQL database
mysql-u root-p ( - u indicates the login user name, and-p indicates the login user password. )
7. View current Database
show databases; (note plus semicolon)
8. Choose to use MySQL Library
Use MySQL
9. Display the current data form
Show tables; (note plus semicolon)
10, MySQL C program implementation of Show Tables function
#include < mysql/mysql.h> #include <stdio.h> #include <stdlib.h>int main () {MySQL *conn; Mysql_res *res; Mysql_row ROW; Char server[] = "localhost"; Char user[] = "root"; Char password[] = "password";//password set when MySQL is installed char database[] = "MySQL"; conn = Mysql_init (NULL); if (!mysql_real_connect (conn, server,user, password, database, 0, NULL, 0)) {fprintf (stderr, "%s\n", Mysql_err OR (conn)); Exit (1); } if (mysql_query (conn, "Show Tables")) {fprintf (stderr, "%s\n", MYSQL_ERROR (conn)); Exit (1); } res = Mysql_use_result (conn); printf ("MySQL Tables in MySQL database:\n"); while (row = mysql_fetch_row (res)) = NULL) {printf ("%s \ n", row[0]); } mysql_free_result (res); Mysql_close (conn); printf ("finish! \ n "); return 0;}
Compilation: Gcc-wall Mysql_test.c-o mysql_test-lmysqlclient
The result of the operation is as follows: The show tables command output above.
Ubuntu Install MySQL Step