[英]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)
port = 3306
ctrl + x , cmd + x y
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
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 -联网
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
mysqld.service changed on disk mysqld.service 在磁盘上更改
systemctl daemon-reload systemctl 守护进程重新加载
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.