如何将mysql的默认端口从3306更改为3360

时间:2021-07-08 18:13:14

I want to change the default port number of MySQL server presently it is 3306. I want to change it to 3360.

我想更改MySQL服务器的默认端口号目前是3306.我想将其更改为3360。

I have tried:

我努力了:

-- port=3360

But things are not working for me. Please provide query to change port not any configuration. I am using Windows 8 64 bit.

但事情对我不起作用。请提供查询以更改端口而不是任何配置。我使用的是Windows 8 64位。

7 个解决方案

#1


16  

You need to edit your my.cnf file and make sure you have the port set as in the following line:

您需要编辑my.cnf文件并确保将端口设置为以下行:

port = 3360

Then restart your MySQL service and you should be good to go. There is no query you can run to make this change because the port is not a dynamic variable (q.v. here for MySQL documentation showing a table of all system variables).

然后重启你的MySQL服务,你应该好好去。没有查询可以运行来进行此更改,因为端口不是动态变量(q.v.此处为MySQL文档,显示所有系统变量的表)。

#2


2  

Go to installed mysql path and find bin folder,open my.ini and search 3306 after that change 3306 to 3360

转到安装的mysql路径并找到bin文件夹,打开my.ini并在将3306更改为3360之后搜索3306

#3


2  

If you're on Windows, you may find the config file my.ini it in this directory

如果您使用的是Windows,则可能会在此目录中找到配置文件my.ini

C:\ProgramData\MySQL\MySQL Server 5.7\

You open this file in a text editor and look for this section:

您在文本编辑器中打开此文件并查找此部分:

# The TCP/IP Port the MySQL Server will listen on
port=3306

Then you change the number of the port, save the file. Find the service MYSQL57 under Task Manager > Services and restart it.

然后更改端口号,保存文件。在任务管理器>服务下找到服务MYSQL57并重新启动它。

#4


1  

When server first starts the my.ini may not be created where everyone has stated. I was able to find mine in C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.6

当服务器首次启动时,可能无法创建my.ini,而每个人都已声明。我能够在C:\ Documents and Settings \ All Users \ Application Data \ MySQL \ MySQL Server 5.6中找到我的

This location has the defaults for every setting.

此位置具有每个设置的默认值。

# CLIENT SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by MySQL client applications.
# Note that only client applications shipped by MySQL are guaranteed
# to read this section. If you want your own MySQL client program to
# honor these values, you need to specify it as an option during the
# MySQL client library initialization.
#
[client]

# pipe
# socket=0.0
port=4306  !!!!!!!!!!!!!!!!!!!Change this!!!!!!!!!!!!!!!!!

[mysql]
no-beep

default-character-set=utf8

#5


0  

Actually, you can just run the service using /mysqld --PORT 1234, it would force mysql to run on the specified port without change the cnf/ini file.

实际上,您可以使用/ mysqld --PORT 1234运行该服务,它会强制mysql在指定端口上运行而不更改cnf / ini文件。

I just cought a case that cnf didn't work. It was weired... so I just use the cmd line as the shortcut and it works!

我只是说一个cnf无效的案例。这是我们的...我只是使用cmd线作为快捷方式,它的工作原理!

#6


0  

The best way to do this is take backup of required database and reconfigure the server.

执行此操作的最佳方法是备份所需的数据库并重新配置服务器。

Creating A Backup

创建备份

The mysqldump command is used to create textfile “dumps” of databases managed by MySQL. These dumps are just files with all the SQL commands needed to recreate the database from scratch. The process is quick and easy.

mysqldump命令用于创建由MySQL管理的数据库的文本文件“转储”。这些转储只是具有从头开始重新创建数据库所需的所有SQL命令的文件。这个过程快速而简单。

If you want to back up a single database, you merely create the dump and send the output into a file, like so:

如果要备份单个数据库,只需创建转储并将输出发送到文件中,如下所示:

mysqldump database_name > database_name.sql

Multiple databases can be backed up at the same time:

可以同时备份多个数据库:

mysqldump --databases database_one database_two > two_databases.sql

In the code above, database_one is the name of the first database to be backed up, and database_two is the name of the second.

在上面的代码中,database_one是要备份的第一个数据库的名称,database_two是第二个的名称。

It is also simple to back up all of the databases on a server:

备份服务器上的所有数据库也很简单:

mysqldump --all-databases > all_databases.sql 

After taking the backup, remove mysql and reinstall it. After reinstalling with the desired port number.

进行备份后,删除mysql并重新安装。重新安装所需的端口号后。

Restoring a Backup

恢复备份

Since the dump files are just SQL commands, you can restore the database backup by telling mysql to run the commands in it and put the data into the proper database.

由于转储文件只是SQL命令,因此可以通过告诉mysql运行其中的命令并将数据放入正确的数据库来恢复数据库备份。

mysql database_name < database_name.sql

In the code above, database_name is the name of the database you want to restore, and database_name.sql is the name of the backup file to be restored..

在上面的代码中,database_name是要还原的数据库的名称,database_name.sql是要还原的备份文件的名称。

If you are trying to restore a single database from dump of all the databases, you have to let mysql know like this:

如果您尝试从所有数据库的转储中恢复单个数据库,则必须让mysql知道如下:

mysql --one-database database_name < all_databases.sql

#7


0  

In Windows 8.1 x64 bit os, Currently I am using MySQL version :

在Windows 8.1 x64位操作系统中,目前我使用的是MySQL版本:

Server version: 5.7.11-log MySQL Community Server (GPL)

For changing your MySQL port number, Go to installation directory, my installation directory is :

要更改MySQL端口号,请转到安装目录,我的安装目录是:

C:\Program Files\MySQL\MySQL Server 5.7

open the my-default.ini Configuration Setting file in any text editor.

在任何文本编辑器中打开my-default.ini配置设置文件。

search the line in the configuration file.

搜索配置文件中的行。

# port = .....

replace it with :

替换为:

port=<my_new_port_number>

like my self changed to :

就像我自己改为:

port=15800

To apply the changes don't forget to immediate either restart the MySQL Server or your OS.

要应用更改,请不要忘记立即重新启动MySQL服务器或操作系统。

Hope this would help many one.

希望这会对很多人有所帮助。

#1


16  

You need to edit your my.cnf file and make sure you have the port set as in the following line:

您需要编辑my.cnf文件并确保将端口设置为以下行:

port = 3360

Then restart your MySQL service and you should be good to go. There is no query you can run to make this change because the port is not a dynamic variable (q.v. here for MySQL documentation showing a table of all system variables).

然后重启你的MySQL服务,你应该好好去。没有查询可以运行来进行此更改,因为端口不是动态变量(q.v.此处为MySQL文档,显示所有系统变量的表)。

#2


2  

Go to installed mysql path and find bin folder,open my.ini and search 3306 after that change 3306 to 3360

转到安装的mysql路径并找到bin文件夹,打开my.ini并在将3306更改为3360之后搜索3306

#3


2  

If you're on Windows, you may find the config file my.ini it in this directory

如果您使用的是Windows,则可能会在此目录中找到配置文件my.ini

C:\ProgramData\MySQL\MySQL Server 5.7\

You open this file in a text editor and look for this section:

您在文本编辑器中打开此文件并查找此部分:

# The TCP/IP Port the MySQL Server will listen on
port=3306

Then you change the number of the port, save the file. Find the service MYSQL57 under Task Manager > Services and restart it.

然后更改端口号,保存文件。在任务管理器>服务下找到服务MYSQL57并重新启动它。

#4


1  

When server first starts the my.ini may not be created where everyone has stated. I was able to find mine in C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.6

当服务器首次启动时,可能无法创建my.ini,而每个人都已声明。我能够在C:\ Documents and Settings \ All Users \ Application Data \ MySQL \ MySQL Server 5.6中找到我的

This location has the defaults for every setting.

此位置具有每个设置的默认值。

# CLIENT SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by MySQL client applications.
# Note that only client applications shipped by MySQL are guaranteed
# to read this section. If you want your own MySQL client program to
# honor these values, you need to specify it as an option during the
# MySQL client library initialization.
#
[client]

# pipe
# socket=0.0
port=4306  !!!!!!!!!!!!!!!!!!!Change this!!!!!!!!!!!!!!!!!

[mysql]
no-beep

default-character-set=utf8

#5


0  

Actually, you can just run the service using /mysqld --PORT 1234, it would force mysql to run on the specified port without change the cnf/ini file.

实际上,您可以使用/ mysqld --PORT 1234运行该服务,它会强制mysql在指定端口上运行而不更改cnf / ini文件。

I just cought a case that cnf didn't work. It was weired... so I just use the cmd line as the shortcut and it works!

我只是说一个cnf无效的案例。这是我们的...我只是使用cmd线作为快捷方式,它的工作原理!

#6


0  

The best way to do this is take backup of required database and reconfigure the server.

执行此操作的最佳方法是备份所需的数据库并重新配置服务器。

Creating A Backup

创建备份

The mysqldump command is used to create textfile “dumps” of databases managed by MySQL. These dumps are just files with all the SQL commands needed to recreate the database from scratch. The process is quick and easy.

mysqldump命令用于创建由MySQL管理的数据库的文本文件“转储”。这些转储只是具有从头开始重新创建数据库所需的所有SQL命令的文件。这个过程快速而简单。

If you want to back up a single database, you merely create the dump and send the output into a file, like so:

如果要备份单个数据库,只需创建转储并将输出发送到文件中,如下所示:

mysqldump database_name > database_name.sql

Multiple databases can be backed up at the same time:

可以同时备份多个数据库:

mysqldump --databases database_one database_two > two_databases.sql

In the code above, database_one is the name of the first database to be backed up, and database_two is the name of the second.

在上面的代码中,database_one是要备份的第一个数据库的名称,database_two是第二个的名称。

It is also simple to back up all of the databases on a server:

备份服务器上的所有数据库也很简单:

mysqldump --all-databases > all_databases.sql 

After taking the backup, remove mysql and reinstall it. After reinstalling with the desired port number.

进行备份后,删除mysql并重新安装。重新安装所需的端口号后。

Restoring a Backup

恢复备份

Since the dump files are just SQL commands, you can restore the database backup by telling mysql to run the commands in it and put the data into the proper database.

由于转储文件只是SQL命令,因此可以通过告诉mysql运行其中的命令并将数据放入正确的数据库来恢复数据库备份。

mysql database_name < database_name.sql

In the code above, database_name is the name of the database you want to restore, and database_name.sql is the name of the backup file to be restored..

在上面的代码中,database_name是要还原的数据库的名称,database_name.sql是要还原的备份文件的名称。

If you are trying to restore a single database from dump of all the databases, you have to let mysql know like this:

如果您尝试从所有数据库的转储中恢复单个数据库,则必须让mysql知道如下:

mysql --one-database database_name < all_databases.sql

#7


0  

In Windows 8.1 x64 bit os, Currently I am using MySQL version :

在Windows 8.1 x64位操作系统中,目前我使用的是MySQL版本:

Server version: 5.7.11-log MySQL Community Server (GPL)

For changing your MySQL port number, Go to installation directory, my installation directory is :

要更改MySQL端口号,请转到安装目录,我的安装目录是:

C:\Program Files\MySQL\MySQL Server 5.7

open the my-default.ini Configuration Setting file in any text editor.

在任何文本编辑器中打开my-default.ini配置设置文件。

search the line in the configuration file.

搜索配置文件中的行。

# port = .....

replace it with :

替换为:

port=<my_new_port_number>

like my self changed to :

就像我自己改为:

port=15800

To apply the changes don't forget to immediate either restart the MySQL Server or your OS.

要应用更改,请不要忘记立即重新启动MySQL服务器或操作系统。

Hope this would help many one.

希望这会对很多人有所帮助。