MySQL学习笔记-MySQL的启动和连接_MySQL
一、查看并启动MySQL服务
在Windows XP下安装完MySQL后,它就已经自动启动服务了,并且在开始菜单中有其客户端的快捷方式连接,见图4.1。

图4.1
可以通过Windows的服务管理器查看。“开始”-“运行”,输入“services.msc”,回车。弹出Windows的服务管理器,然后就可以看见服务名为“mysql”的服务项了,其右边标明“已启动”,见图4.2。

图4.2
如果没有“已启动”字样,说明MySQL服务未启动,不能连接,会出现10061错误。启动方法为:“开始”-“运行”,输入“cmd”,回车弹出XP命令提示符界面(类似DOS命令行,以后简称命令行)。然后输入“net start mysql”就启动mysql服务了,停止mysql服务“net stop mysql”(注意,这里是输入的MySQL服务的名字。如果你的MySQL服务的名字是DB或其它名字,你应该输入“net start DB”或其它名),见图4.3。

图4.3
二、连接MySQL服务器
现在开始连接MySQL服务器,连接MySQL的命令格式为:
mysql –h 主机名 –u 用户名 –p 用户密码
在命令行进入MySQL的目录,见图4.4。

图4.4
由于我在开始时没有设置密码,所以直接按回车就可以了。如果出现:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.11-nt
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
这就说明连接MySQL成功,“mysql>”说明已经成功联入MySQL服务器了,可以开始msql的操作了。
“-h 主机名”还可以这样写:“-h主机名”(中间不要空格)、“--host=主机名”
“-u 用户名”还可以写成:“-u 用户名”、“--user=用户名”
“-p 用户密码”还可以写出:“--password=用户密码”。但是,出于安全的考虑,最好不要这样做。选择-p 不跟口令告诉mysql在启动时提示您键入口令。例如:
mysql>mysql -hlocalhost -uroot -p
三、一点小技巧
象这样连接MySQL服务器很麻烦,需要先进入MySQL的目录,再连接MySQL。这里有个小技巧可以快速连接MySQL服务器。
“开始”-“所有程序”-“附件”-“命令行提示符”,在上面点右键,“发送到”-“桌面快捷方式”,在桌面上做个cmd的快捷方式。
然后右键点击这个快捷方式,“属性”-“常规”选项卡,将名称改为“MySQL命令行”。转到“快捷方式”选项卡,将起始位置改为"E:\MySQL Server 4.1\bin",包括引号。
下次连接MySQL服务器时,点击这个快捷方式就直接进入Mysql的目录了,直接输入连接命令即可。
还有个更方便的技巧,见图4.1。上面有个“MySQL Command Line Client”,点击它,出现“Enter password:”提示,输入密码,马上就连接上MySQL服务器,连接命令都不用敲了。不过建议还是用上面的敲命令方式,可以熟悉命令的使用。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Big data structure processing skills: Chunking: Break down the data set and process it in chunks to reduce memory consumption. Generator: Generate data items one by one without loading the entire data set, suitable for unlimited data sets. Streaming: Read files or query results line by line, suitable for large files or remote data. External storage: For very large data sets, store the data in a database or NoSQL.

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

Oracle database and MySQL are both databases based on the relational model, but Oracle is superior in terms of compatibility, scalability, data types and security; while MySQL focuses on speed and flexibility and is more suitable for small to medium-sized data sets. . ① Oracle provides a wide range of data types, ② provides advanced security features, ③ is suitable for enterprise-level applications; ① MySQL supports NoSQL data types, ② has fewer security measures, and ③ is suitable for small to medium-sized applications.
