user1308373
user1308373

Reputation: 229

How can I change mysql port from 0 to 3306?

I find it hard to establish a link between JDBC and MySQL. I think one of the reasons is the mysql port. I checked the port with the statement: show variables like 'port'; in mysql. And the response is:

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

My operating system is archlinux. How can I change mysql port from 0 to 3306?

I have changed the port number in both /etc/my.cnf and /etc/mysql/my.cnf. But it didn't work.

Upvotes: 22

Views: 33085

Answers (9)

Mhamed Hmimid
Mhamed Hmimid

Reputation: 11

Two days of searching the internet for an error that drupal 10  gave me 

   

<!-- begin snippet: js hide: false console: true babel: false -->

to find that i ve got to do this following the skip networking = off
with my.cnf 

 # Use default MacPorts settings
!include /opt/local/etc/mysql57/macports-default.cnf
~                                                      
and macports-default.cnf :

 # MacPorts default options
[mysqld]
# skip-networking so multiple mysql server ports can be loaded
# without each competing for port 3306.
skip-networking 

changed skip-networking = off

and everything done
thanks a lot

Upvotes: 0

BongSey
BongSey

Reputation: 161

I met the same error in my MySQL8-community after I reset root's PWD by running mysqld --skip-grant-tables --skip-networking.

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

    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

  1. remove the override.conf

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

  2. mysqld.service changed on disk

    systemctl daemon-reload

  3. restart MySQL

    systemctl restart mysqld

Upvotes: 0

Ravinath
Ravinath

Reputation: 1750

allow remote connection fixed, didn't change " GLOBAL VARIABLES LIKE 'PORT';" edit 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

Upvotes: -1

DavidArndt
DavidArndt

Reputation: 446

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:

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

Run ps aux | grep mysql and you may see the process (or a pair of them) hanging around still. If so, kill it/them and then restart mysql.

Upvotes: 0

erdem
erdem

Reputation: 11

You need to change this value from mysql configuration file. Steps are:

  • To go to related file: sudo nano /etc/mysql/my.cnf

  • To search for related line:(for Win, Linux) ctrl + w , (for Mac) cmd + w

port = 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

Upvotes: 1

Flo Doe
Flo Doe

Reputation: 5381

First of all check what 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).

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. After this procedure you have to restart your mysqld.

Normaly there is no need to set the port 3306 explicitly since 3306 is the default port for mjysqld to listen on.

Upvotes: 17

drew212
drew212

Reputation: 506

You need to edit your mysql config file, my.cnf in /etc/my.cnf and change the port to 3306. Then restart mysql.

Source: 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

It has a portion talking about copying over your my.cnf file:

Copy your choice of config file:

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

Upvotes: 0

Thomas Wright
Thomas Wright

Reputation: 1309

You can change the port number in the MySQL config file: my.cnf

Upvotes: 0

FreudianSlip
FreudianSlip

Reputation: 2920

On my ubuntu install, in /etc/mysql/my.cnf theres a line that says :

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

Try changing this value accordingly and restarting mysql.

Hope it works for you.

Upvotes: 2

Related Questions