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).
<code>mysql -u root -p</code>
my_database
: <code>CREATE DATABASE my_database;</code>
<code>USE my_database;</code>
my_table
: <code>CREATE TABLE my_table ( id INT NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL, PRIMARY KEY (id) );</code>
my_table
table : <code>INSERT INTO my_table (name) VALUES ('John Doe');</code>
LOAD DATA INFILE
command to import data from a CSV file: <code>LOAD DATA INFILE 'data.csv' INTO TABLE my_table;</code>
SELECT
command to query the data in the table: <code>SELECT * FROM my_table;</code>
WHERE
clause to filter the results: <code>SELECT * FROM my_table WHERE name = 'John Doe';</code>
COUNT()
, SUM()
and AVG()
:<code>SELECT COUNT(*) FROM my_table;</code>
UPDATE
command to update the data in the table: <code>UPDATE my_table SET name = 'Jane Doe' WHERE id = 1;</code>
WHERE
clause to select the rows to be updated. DELETE
command to delete data from the table: <code>DELETE FROM my_table WHERE id = 1;</code>
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!