Open your terminal. This is where you’ll enter your commands to interact with MySQL.
username
with your MySQL username (usually root
) and password
with your actual password.mysql -u username -p
After pressing Enter, you’ll be prompted to enter the password.To view all databases:
SHOW DATABASES;
To create a new database named exampledb
:
CREATE DATABASE exampledb;
Select the exampledb
database to perform operations on it:
USE exampledb;
Create a table named users
:
CREATE TABLE users ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100), email VARCHAR(100), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
To list all tables in the current database:
SHOW TABLES;
Get details about the structure of a table:
DESCRIBE users;
Add a new record into the users
table:
INSERT INTO users (name, email) VALUES ('John Doe', 'johndoe@example.com');
Retrieve all records from the users
table:
SELECT * FROM users;
Retrieve specific columns:
SELECT name, email FROM users;
Retrieve records with conditions:
SELECT * FROM users WHERE name='John Doe';
Update existing records:
UPDATE users SET email='john.doe@example.com' WHERE name='John Doe';
Remove records from a table:
DELETE FROM users WHERE name='John Doe';
To exit the MySQL command line, type:
EXIT;
or
QUIT;
mysqldump
command to back up databases and the mysql
command to restore.HELP
in the MySQL command line for assistance or \h
for a list of commands.By following these steps and examples, you should be able to manage and manipulate MySQL databases directly from the Linux command line effectively.
This guide provides a detailed walkthrough of installing and configuring an Apache web server and…
WordPress development has evolved significantly, and modern tooling plays a crucial role in creating efficient…
I. Project Overview The goal is to automate the process of notifying search engines (like…
1. Database Structure (MySQL) We'll need a database table to store information about our website's…
This explanation aims to provide a solid foundation for understanding the process and implementing your…
Okay, here's a comprehensive guide on building a real-time website chat script using PHP, HTML,…