How do you connect to a local database in MySQL?
To connect to a local database, you can follow these steps:
- Install the MySQL database server by downloading the installation program suitable for your operating system from the official MySQL website and following the instructions for installation.
- Start the MySQL server. Depending on your operating system, you can enter mysql.server start or mysqld in the command line to start the MySQL server.
- Open the command line terminal (Windows users can use Command Prompt or PowerShell, macOS and Linux users can use Terminal).
- Enter the following command to connect to the MySQL database server:
mysql -u 用户名 -p
Replace “username” with the username you use to connect to the database. Then press Enter.
- Enter the password and then press the Enter key. If you haven’t set a password, you can simply press Enter.
- After successfully logging in, you will see the MySQL prompt (mysql>), indicating that you have successfully connected to the local MySQL database.
You can now execute various MySQL commands to manage and query the database.