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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29866204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 16:06:43  来源:igfitidea点击:

How to change the default port of mysql from 3306 to 3360

mysqlsqldatabaseport

提问by programminglover

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 位。

回答by Tim Biegeleisen

You need to edit your my.cnffile 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 portis not a dynamic variable (q.v. here for MySQL documentationshowing a table of all system variables).

然后重新启动您的 MySQL 服务,您应该一切顺利。没有可以运行的查询来进行此更改,因为port它不是动态变量(此处为显示所有系统变量表的MySQL 文档的qv )。

回答by Emmanuel N K

If you're on Windows, you may find the config file my.iniit 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 并重新启动它。

回答by Gergely Bacso

On newer (for example 8.0.0) the simplest solution is (good choice for a scripted start-up for example):

在较新的(例如 8.0.0)上,最简单的解决方案是(例如脚本启动的好选择):

mysqld --port=23306

回答by M.Minbashi

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,然后将3306更改为3360

回答by ddavisqa

When server first starts the my.inimay 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

回答by Weijing Jay Lin

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 行作为快捷方式并且它有效!

回答by Liger

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

回答by ArifMustafa

In Windows 8.1 x64 bitos, Currently I am using MySQLversion :

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

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

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

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

C:\Program Files\MySQL\MySQL Server 5.7

open the my-default.iniConfiguration Settingfile 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.

希望这会帮助很多人。