Beginner's "Linux Programming" learning (8): MySQL database installation, configuration and basic operations

Source: Internet
Author: User

1. mysql Database:When it comes to the development of some large web systems or embedded software, it is necessary to use a database to manage the data. In the Windows operating system, using a variety of databases, such as: SQL Server, Oracle, MySQL, and so on, we know that the Windows system software installation configuration is interface-style, operation is obvious and simple. So on the Linux operating system, for the database selection, as if the most preferred is MySQL, it is a relational database management system, developed by the Swedish MySQL AB company, currently belongs to the Oracle company. MySQL is an associated database management system that keeps data in separate tables rather than putting all of the data in a large warehouse, which increases speed and increases flexibility. MySQL's SQL language is the most commonly used standardized language for accessing databases. MySQL software uses a dual licensing policy (this term "authorization policy"), it is divided into community and commercial version, because of its small size, speed, low total cost of ownership, especially the open source of this feature, the general small and medium-sized web site development has chosen MySQL as the site database. Thanks to the performance of its community edition, PHP and Apache make a good development environment. Today, I read the "Linux Programming" section of MySQL, which is documented in the following steps to install the configuration in a virtual machine for future study reviews. 2. mysql installation steps: 2.1 To see if your system already exists because MySQL database is too popular on Linux, so the mainstream Linux version of the current download basically integrates the MySQL database inside, We can check if the MySQL database is already installed on our operating system using the following command:
[Email protected] ~]# Rpm-qa | grep MySQL

We use the root account to log into the system, because I have installed MySQL on my system, so I get the installed version information on the system:
If it is not installed, there will be no installation prompts, you can skip the uninstall Step 2. 2.2 Uninstall the original MySQL using the following command, uninstall the existing MySQL:
[[email protected] ~]# rpm-e--nodeps MySQL
At this point, the MySQL installation record is no longer present in the system. 2.3 Yum way to install MySQL through the Yum way to the MySQL database installation, first we can enter the Yum list | grep mysql command to view the downloadable version of the MySQL database available on Yum:

[[Email protected] ~] #yum List | grep MySQL

We can see that there are many downloadable versions of MySQL on the Yum server:

We then installed the MySQL mysql-server mysql-devel by entering the Yum install-y mysql-server mysql mysql-devel command
[email protected] ~]# yum install-y mysql-server MySQL mysql-devel

After a few seconds, we can see the following information:

When we see complete, this pleasing word, we have successfully installed the MySQL database. 3. mysql Database configuration 3.1 MySQL service settings after installing the MySQL database, you will find a mysqld service, this is our database service, we enter service mysqld start command to start our MySQL service.

Generally we set the service of the database to boot, use the command Chkconfig mysqld on to set, and use the command Chkconfig--list | grep MySQL to see the results:
[[email protected] ~]# chkconfig mysqld on[[email protected] ~]# chkconfig--list | grep mysqlmysqld         0:off1:off2:on3:on4:on5:on6:of

3.2 Account password settings After we have installed the MySQL database, there is a default administrator account called Root, at which point you need to manually set the password: After using the command mysqladmin-u root password ' root ' to set the password, We can log in to the database by command mysql-u root-p:
At this point, for the MySQL database configuration, you can end it. 4. MySQL Basic Operation 4.1 Basic configuration file (1) The main configuration information of MySQL database is stored in/etc/my.cnf, view:

(2) The database file is stored in/var/lib/mysql, and the view:
[Email protected] mysql]# cd/var/lib/mysql[[email protected] mysql]# ls-ltotal 20500-rw-r--r--. 1 root  root     10717 10:34 create-rw-rw----. 1 mysql mysql 10485760 may 10:27 ibdata1-rw-rw----. 1 MySQL my SQL  5242880 may 10:27 ib_logfile0-rw-rw----. 1 mysql mysql  5242880 the 10:27 ib_logfile1drwx------. 2 MySQL MySQL     4096 10:27 mysqlsrwxrwxrwx 1 mysql mysql        0 may 10:27 mysql.sockdrwx------. 2 mysql MySQL     
4.2 Database Basic Operations (1) Create a database from the above default file can be seen, our MySQL database has two default database, one is MySQL, the other is test. We create a database of our own, with the following commands:
[Email protected] mysql]# mysql-u root-penter password:welcome to the MySQL monitor.  
First of all, we log in to the database with the root account, we can see the mysql> command prompt symbol, execute the CREATE DATABASE command, the name; Get the Create success message and exit the database using the command exit. Now we can see the database yr that has been created under/var/lib.mysql:
[Email protected] mysql]# ls-ltotal 20504-rw-r--r--. 1 root  root     10717 10:34 create-rw-rw----. 1 mysql mysql 10485760 may 10:27 ibdata1-rw-rw----. 1 MySQL my SQL  5242880 may 10:27 ib_logfile0-rw-rw----. 1 mysql mysql  5242880 the 10:27 ib_logfile1drwx------. 2 MySQL  MySQL     4096 10:27 mysqlsrwxrwxrwx 1 mysql mysql        0 may 10:27 mysql.sockdrwx------. 2 mysql mysql     4096 May 10:27 testdrwx------. 2 MySQL MySQL     
(2) Build the table and add the data below, log in again MySQL we built the table in the database created above and added several data:
[Email protected] mysql]# mysql-u root-penter password:welcome to the MySQL monitor.  Commands End With; or \g.your MySQL connection ID is 23Server version:5.1.73 Source distributioncopyright (c) (+), Oracle and/or its Affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names trademarks of their respectiveowners. Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.mysql> use yr;database changedmysql> CREATE TABLE user (    Id INTEGER auto_increment not NULL PRIMARY KEY,    Name VARCHAR (50),    

At this point, a successful user table is created in the YR database, with ID, Name, and age three attributes, where the ID is the primary key. To add and query data:
mysql> INSERT INTO User (Id, Name, age) VALUES (1, "AA", 20); Query OK, 1 row affected (0.10 sec) mysql> insert into user (Id, Name, age) VALUES (2, "BB", 21); Query OK, 1 row Affected (0.00 sec) mysql> Select Id, Name, age from user;+----+------+------+| Id | Name | Age  |+----+------+------+|  1 | AA   |   | |  2 | BB   |   |+----+------+------+
(3) Delete data from a database table below we delete a id=1 of data:
mysql> Delete from user where id=1; Query OK, 1 row affected (0.05 sec) mysql> Select Id, Name, age from user;+----+------+------+| Id | Name | Age  |+----+------+------+|  2 | BB   |   

(4) Delete database tables and databases delete database tables and databases using the drop command:
mysql> drop table user; Query OK, 0 rows affected (0.02 sec)
mysql> drop database yr; Query OK, 0 rows affected (0.28 sec) mysql> Exitbye[[email protected] mysql]# lltotal 20500-rw-r--r--. 1 root  root     10717 10:34 create-rw-rw----. 1 mysql mysql 10485760 may 10:27 ibdata1-rw-rw----. 1 MySQL my SQL  5242880 may 10:27 ib_logfile0-rw-rw----. 1 mysql mysql  5242880 the 10:27 ib_logfile1drwx------. 2 MySQL MySQL     4096 10:27 mysqlsrwxrwxrwx 1 mysql mysql        0 may 10:27 mysql.sockdrwx------. 2 mysql MySQL     

These are the entire contents of the Linux system for MySQL installation, configuration, and use.

Beginner's "Linux Programming" learning (8): MySQL database installation, configuration and basic operations

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.