MySQL/Ubuntu

来自康健生活

ubuntu

/home/kangkk
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install mysql-server mysql-client

服务器IP地址

/home/kangkk
sudo ifconfig eth0 | grep inet | awk '{ print $2 }'

MYSQL初始化命令

/home/kangkk
mysql_secure_installation

查看版本

[jian@kang /home/kangkk]$
mysqladmin version
mysqladmin  Ver 9.1 Distrib 10.1.23-MariaDB, for debian-linux-gnu on x86_64
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Server version          10.1.23-MariaDB-9+deb9u1
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /var/run/mysqld/mysqld.sock
Uptime:                 33 min 5 sec

Threads: 1  Questions: 79  Slow queries: 0  Opens: 17  Flush tables: 1  Open tables: 11  Queries per second avg: 0.039

如果能够看到mysql的版本信息,证明目前MySQL没有口令,设置密码

/home/kangkk
mysqladmin password xxxxxx

更改配置文件。

/etc/mysql/my.cnf
...
# 打开3306端口监听
skip-networking
...
# 远程的机器能够访问MySQL数据库服务,可以通过改bind-address来实现
bind-address = 0.0.0.0
...

重新启动MySQL

/home/kangkk
/etc/init.d/mysql restart

修改ROOT密码还有另一种方法

/etc/mysql/debian.cnf
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = root
password =
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = root
password = 
socket   = /var/run/mysqld/mysqld.sock
basedir  = /usr

查看端口。

[jian@kang /home/kangkk]$
lsof -i:3306
COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mysqld  23692 mysql   39u  IPv4  55255      0t0  TCP localhost:mysql (LISTEN)