Home > Database > Mysql Tutorial > Let's talk about the installation and use of mysql

Let's talk about the installation and use of mysql

PHPz
Release: 2023-04-21 13:52:28
Original
666 people have browsed it

MySQL is a popular open source relational database management system, and many web applications use MySQL to store data. MySQL has multiple versions available for download, including MySQL Server, MySQL Workbench, etc. This article will introduce the installation and use of MySQL.

1. MySQL installation

  1. Download the MySQL installation package

On the MySQL official website (https://dev.mysql.com/downloads/mysql /) to download the compressed package of MySQL Server. Choose the version that suits your operating system and computer architecture.

  1. Extract the installation package

Use the decompression tool to decompress the MySQL Server compressed package into a directory on your computer.

  1. Configuring MySQL

Open the decompressed MySQL folder. Rename the "my-default.ini" file to "my.ini" and open it. Find the [mysqld] section and edit the following lines:

basedir = mysql解压缩文件夹的位置
datadir = mysql解压缩文件夹的位置\data
Copy after login

Change "The location of the mysql unzipped folder" to the actual location of the MySQL unzipped folder.

  1. Start MySQL

In the MySQL decompression folder, find the "bin" folder, open the command prompt or terminal, and enter the following command to start MySQL:

cd /path/to/mysql/folder/bin
mysqld --console
Copy after login

"/path/to/mysql/folder" is the actual location of the MySQL unzipped folder.

If MySQL starts successfully, the terminal will display the message "Listening to port 3306".

  1. Create an administrator account

In a command prompt or terminal, enter the following command to create an administrator account:

mysql -u root -p
Copy after login

Prompts you for a password. Since this is a newly installed MySQL and there is no password, just press Enter. Enter the following command:

CREATE USER 'admin'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;
Copy after login

Please change "your_password" to your desired password.

2. MySQL uses

  1. to log in to MySQL

In the command prompt or terminal, enter the following command to log in to MySQL as an administrator user:

mysql -u admin -p
Copy after login

Prompts you for your password. Enter the password you created during installation.

  1. Create database and tables

In MySQL, use the following command to create the database:

CREATE DATABASE mydatabase;
Copy after login

Use the following command to create the table:

USE mydatabase;
CREATE TABLE mytable (
    id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    firstname VARCHAR(30) NOT NULL,
    lastname VARCHAR(30) NOT NULL,
    email VARCHAR(50),
    reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
Copy after login

This command will create a table named "mytable" with an auto-increment ID, first and last name, email and timestamp.

  1. Insert data

Use the following command to insert data into the table:

INSERT INTO mytable (firstname, lastname, email) VALUES ('John', 'Doe', 'john@email.com');
Copy after login
  1. Query data

Use the following query to retrieve data from the table:

SELECT * FROM mytable;
Copy after login

This command will return data for all rows in the "mytable" table.

  1. Update data

Use the following command to update an existing row in the table:

UPDATE mytable SET email='new_email@email.com' WHERE id=1;
Copy after login

This command updates the email with row ID 1 is "new_email@email.com".

  1. Delete data

Use the following command to delete rows in the table:

DELETE FROM mytable WHERE id=1;
Copy after login

This command will delete the row with row ID 1 from the table .

Summary:

This article introduces how to download, install and use MySQL. After completing the installation, you learned how to create databases and tables, insert data, query, update, and delete data. MySQL is a powerful tool capable of storing and managing large amounts of data, making it ideal for web applications.

The above is the detailed content of Let's talk about the installation and use of 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