Home > Database > Mysql Tutorial > linux forgets mysql

linux forgets mysql

PHPz
Release: 2023-05-23 10:11:07
Original
479 people have browsed it

Linux is a widely used operating system, and MySQL is an important database management system in the Linux system. However, in daily use, we often forget the installation, configuration and use of MySQL for various reasons. The following details how to install, configure and use MySQL in Linux systems.

Step One: Install MySQL

Installing MySQL in a Linux system is very simple. Use the following command to install MySQL:

sudo apt-get install mysql-server

During the installation process, you will be prompted to enter the MySQL administrator user password and confirmation password. After the installation is complete, you can use the following command to check whether MySQL is running normally:

sudo service mysql status

Step 2: Configure MySQL

MySQL’s configuration file is in /etc/ mysql/my.cnf. In this file, you can perform various configurations on MySQL:

● Change the default character set of MySQL

By default, the character set used by MySQL is latin1. In order to avoid garbled characters, we can change the character set to utf8. Find the following two lines in the configuration file:

character-set-server = latin1

collation-server = latin1_swedish_ci

Change them to:

character-set-server = utf8

collation-server = utf8_general_ci

Then restart the MySQL service for the changes to take effect:

sudo service mysql restart

● Change the listening address of MySQL

By default, MySQL only listens locally. If we want to allow other computers to access MySQL, we need to change the listening address in the configuration file. Find the following line in the my.cnf file:

bind-address = 127.0.0.1

Change it to:

bind-address = 0.0.0.0

This will allow other computers to access MySQL via IP address.

Step 3: Use MySQL

After installing and configuring MySQL, we can use the following command to log in to MySQL:

mysql -u root -p

Among them, "-u" is the user name, and "-p" means entering the password. After entering the password, we will see the MySQL command line prompt. In MySQL, we can perform various database operations.

● Create a new database

Use the following command to create a new database:

CREATE DATABASE mydb;

"mydb" is the name of the database to be created .

● Create a new table

Use the following command to create a new table in the database:

CREATE TABLE mytable ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, name VARCHAR( 30) NOT NULL, email VARCHAR(50) NOT NULL );

This command will create a table named "mytable", which contains 3 fields: id, name and email.

● Insert data

Use the following command to insert new data into the table:

INSERT INTO mytable (name, email) VALUES ('John Smith', 'john.smith @example.com');

This command will insert a new piece of data into the table. The data includes two fields: name and email.

● Query data

Use the following command to query data from the table:

SELECT * FROM mytable;

This command will return all data of the table Record.

Summary:

Using MySQL in a Linux system is very simple, and only requires a few simple steps to complete installation, configuration and use. Therefore, if we need to use a database to store and query data, MySQL is a good choice. I hope this article can help you better understand and use MySQL.

The above is the detailed content of linux forgets mysql. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template