Home >Database >Mysql Tutorial >How to use mysql after downloading it

How to use mysql after downloading it

下次还敢
下次还敢Original
2024-04-05 18:09:18762browse

After downloading and installing MySQL, you need to perform the following steps to use MySQL: Log in to MySQL. Create database. Create table. Insert data. Query data. Update data (if needed). Delete data (if necessary).

How to use mysql after downloading it

How to use MySQL after downloading

Install MySQL

  1. Go to the MySQL official website to download the file that is suitable for your operating system The latest MySQL version.
  2. Run the installer and follow the prompts.
  3. Select the "Custom" installation type and specify the MySQL data directory and port.
  4. Set the root user's password.
  5. After completing the installation, start the MySQL service.

Create database and tables

  1. Use the following command to log in to MySQL:
<code>mysql -u root -p</code>
  1. Enter the root password set during the installation process .
  2. Create a new database named my_database:
<code>CREATE DATABASE my_database;</code>
  1. Switch to the new database:
<code>USE my_database;</code>
  1. Create a new table named my_table:
<code>CREATE TABLE my_table (
  id INT NOT NULL AUTO_INCREMENT,
  name VARCHAR(255) NOT NULL,
  PRIMARY KEY (id)
);</code>

Insert data

  1. Insert data into the my_table table :
<code>INSERT INTO my_table (name) VALUES ('John Doe');</code>
  1. You can also use the LOAD DATA INFILE command to import data from a CSV file:
<code>LOAD DATA INFILE 'data.csv' INTO TABLE my_table;</code>

Query data

  1. Use the SELECT command to query the data in the table:
<code>SELECT * FROM my_table;</code>
  1. You can use the WHERE clause to filter the results:
<code>SELECT * FROM my_table WHERE name = 'John Doe';</code>
  1. Various aggregate functions can be used, such as COUNT(), SUM() and AVG():
<code>SELECT COUNT(*) FROM my_table;</code>

Update data

  1. Use the UPDATE command to update the data in the table:
<code>UPDATE my_table SET name = 'Jane Doe' WHERE id = 1;</code>
  1. can be combinedWHERE clause to select the rows to be updated.

Delete data

  1. Use the DELETE command to delete data from the table:
<code>DELETE FROM my_table WHERE id = 1;</code>
  1. can be combined WHERE clause to select rows to delete.

The above is the detailed content of How to use mysql after downloading it. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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