mysql> show global variables like 'port'; 是0
打开目录
/etc/mysql/mysql.conf.d
修改这段话为
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
datadir = /var/lib/mysql
#skip-grant-tables
# If MySQL is running as a replication slave, this should be
# changed. Ref https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_tmpdir
# tmpdir = /tmp
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 127.0.0.1
mysqlx-bind-address = 127.0.0.1
其中skip-grant-tables 这个应该是免密码登录,给注释掉,我也不知道为什么跟端口0相关
然后重启数据库
systemctl restart mysql
然后
登录数据库
mysql -uroot -p 123456 1234456是我的密码
然后查看
netstat -lanp | grep 3306
tcp 0 0 127.0.0.1:33060 0.0.0.0:* LISTEN 122309/mysqld
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 122309/mysqld
启动成功 为什么还有个33060不知道