简体   繁体   English

如何将mysql端口从0更改为3306?

[英]How can I change mysql port from 0 to 3306?

I find it hard to establish a link between JDBC and MySQL.我发现很难在 JDBC 和 MySQL 之间建立链接。 I think one of the reasons is the mysql port.我认为原因之一是mysql端口。 I checked the port with the statement: show variables like 'port';我用语句检查了端口: show variables like 'port'; in mysql.在 mysql 中。 And the response is:回应是:

+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 0     |
+---------------+-------+
1 row in set (0.07 sec)

My operating system is archlinux.我的操作系统是archlinux。 How can I change mysql port from 0 to 3306?如何将mysql端口从0更改为3306?

I have changed the port number in both /etc/my.cnf and /etc/mysql/my.cnf.我已经更改了 /etc/my.cnf 和 /etc/mysql/my.cnf 中的端口号。 But it didn't work.但它没有用。

First of all check what SHOW VARIABLES LIKE 'skip_networking';首先检查SHOW VARIABLES LIKE 'skip_networking'; if it reports skip_networking = On, your mysqld is started without networking support (which leads to an value of 0 in the port system variable).如果它报告skip_networking = On,则您的mysqld 在没有网络支持的情况下启动(这导致端口系统变量中的值为0)。

If this is the case, you most likely have to check the init scripts for your mysqld, its most likely under /etc/init.d/mysql , search here for --skip-networking and comment out (delete) this part.如果是这种情况,您很可能必须检查 mysqld 的 init 脚本,它很可能在/etc/init.d/mysql下,在此处搜索--skip-networking并注释掉(删除)这部分。 After this procedure you have to restart your mysqld.在此过程之后,您必须重新启动 mysqld。

Normaly there is no need to set the port 3306 explicitly since 3306 is the default port for mjysqld to listen on.通常不需要显式设置端口 3306,因为 3306 是 mjysqld 侦听的默认端口。

On my ubuntu install, in /etc/mysql/my.cnf theres a line that says :在我的 ubuntu 安装中,在 /etc/mysql/my.cnf 中有一行写着:

[mysqld]
port = 3306
<snip...>

Try changing this value accordingly and restarting mysql.尝试相应地更改此值并重新启动 mysql。

Hope it works for you.希望对你有效。

You need to change this value from mysql configuration file.您需要从 mysql 配置文件中更改此值。 Steps are:步骤是:

  • To go to related file: sudo nano /etc/mysql/my.cnf转到相关文件: sudo nano /etc/mysql/my.cnf

  • To search for related line:(for Win, Linux) ctrl + w , (for Mac) cmd + w搜索相关行:(Win, Linux) ctrl + w , (Mac) cmd + w

port = 0端口 = 0

(look for twice for [client] and [mysqld] sections)
  • Replace your new value替换您的新值
port = 3306
  • Save and Exit保存并退出
ctrl + x , cmd + x y
  • Restart service重启服务

sudo service mysql restart须藤服务 mysql 重启

I had this problem because I had forgotten that I started mysqld with the --skip-networking flag in order to reset the MySQL root password, like so:我遇到了这个问题,因为我忘记了使用--skip-networking标志启动 mysqld 以重置 MySQL 根密码,如下所示:

sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &

Run ps aux | grep mysql运行ps aux | grep mysql ps aux | grep mysql and you may see the process (or a pair of them) hanging around still. ps aux | grep mysql ,您可能会看到该过程(或其中一对)仍然存在。 If so, kill it/them and then restart mysql.如果是这样,杀死它/他们,然后重新启动 mysql。

I met the same error in my MySQL8-community after I reset root's PWD by running mysqld --skip-grant-tables --skip-networking.通过运行 mysqld --skip-grant-tables --skip-networking 重置 root 的 PWD 后,我在 MySQL8 社区中遇到了同样的错误。

FLUSH PRIVILEGES; can't help for that even adding skip-networking =OFF and adding port=3306 in my.cnf and restart still can't help. then I found this solution
  1. check which files override my.cnf检查哪些文件覆盖了 my.cnf

    sudo grep -rnw '/etc/' -e 'skip-networking sudo grep -rnw '/etc/' -e 'skip-networking

/etc/systemd/system/mysqld.service.d/override.conf:3:ExecStart=/usr/sbin/mysqld --skip-grant-tables --skip-networking /etc/my.cnf:28:#skip-networking /etc/systemd/system/mysqld.service.d/override.conf:3:ExecStart=/usr/sbin/mysqld --skip-grant-tables --skip-networking /etc/my.cnf:28:#skip -联网

  1. remove the override.conf删除override.conf

    rm -rf /etc/systemd/system/mysqld.service.d/override.conf rm -rf /etc/systemd/system/mysqld.service.d/override.conf

  2. mysqld.service changed on disk mysqld.service 在磁盘上更改

    systemctl daemon-reload systemctl 守护进程重新加载

  3. restart MySQL重启 MySQL

    systemctl restart mysqld systemctl 重启 mysqld

You need to edit your mysql config file, my.cnf in /etc/my.cnf and change the port to 3306. Then restart mysql.您需要编辑您的 mysql 配置文件,/etc/my.cnf 中的 my.cnf 并将端口更改为 3306。然后重新启动 mysql。

Source: http://www.cyberciti.biz/faq/change-default-mysql-port-under-linuxunix/来源: http : //www.cyberciti.biz/faq/change-default-mysql-port-under-linuxunix/

Edit:编辑:

This website might help you a bit more for your specific platform: https://wiki.archlinux.org/index.php/MySQL#Configuration该网站可能会为您的特定平台提供更多帮助: https : //wiki.archlinux.org/index.php/MySQL#Configuration

It has a portion talking about copying over your my.cnf file:它有一部分谈论复制您的 my.cnf 文件:

Copy your choice of config file:复制您选择的配置文件:

# cp /usr/local/mysql/support-files/my-medium.cnf /usr/local/mysql/data/my.cnf

您可以在 MySQL 配置文件中更改端口号:my.cnf

allow remote connection fixed, didn't change " GLOBAL VARIABLES LIKE 'PORT';"允许远程连接固定,没有改变“GLOBAL VARIABLES LIKE 'PORT';” edit my.cnf /etc/my.cnf编辑 my.cnf /etc/my.cnf

[mysqld]
user            = mysql
basedir         = /usr
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
datadir         = /var/lib/mysql
tmpdir          = /tmp
language        = /usr/share/mysql/English
bind-address    = 65.55.55.2
# your mysql server ip address should place in bind-address
# skip-networking

restart the mysql service重启mysql服务

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将mysql的默认端口从3306更改为3360 - How to change the default port of mysql from 3306 to 3360 找不到 MySql 端口 3306 - Can't find MySql port 3306 无法启动MySQL,3306端口忙 - Can't start MySQL, port 3306 busy 如何解决wamp上的mysql端口3306错误? - How to resolve mysql port 3306 error on wamp? 如何修复:MySQL 无法启动:错误“另一个 mysqld 服务器在端口 3306 上运行?” - 检查端口,它是免费的 - How to fix: MySQL can not start: Error "another mysqld server running on port: 3306?" - checked port and it is FREE 如果我在安装过程中更改了MySQL的默认端口号(3306),会不会有什么问题? - If I change the default port number (3306) of MySQL during installation, then will it cause any problem? 如何解绑3306端口? - How can one unbind port 3306? 我更改端口号而不是3306时无法连接到mysql - Can't connect to mysql when I changed its port number rather than 3306 可以在13306端口配置mysql Replication,在3306端口正常运行数据库吗? - Can I configure mysql Replication on port 13306 and normal database operation on 3306? 我无法使用mysql端口号3306访问数据库并在laravel项目中迁移 - I can't access database and migrate in laravel project using port number 3306 for mysql
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM