- 使用超级用户,不需要老提示需要sudo
su root
如果没有更新apt-get 可以先更新一下
apt-get update
开始按装数据库,不需要下载包安装,麻烦
apt-get install mysql-server
安装时,有一个提示请输入Y
After this operation, 262 MB of additional disk space will be used. Do you want to continue? [Y/n] y
安装完server后,再安装一下client,方便配置
apt-get install mysql-client
安装完后配置
sudo mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No: n
Please set the password for root here.
New password:
Re-enter new password:
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : n
... skipping.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n
... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : n
... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
All done!
登录数据库
mysql -u root -p
配置远程连接
--切换到 mysql库 use mysql; --修改root 的host信息,默认root中有localhost能登录 update user set host='%' where user='root'; --更改加密方式,并设置密码 alter user 'root'@'%' IDENTIFIED WITH mysql_native_password by '登录密码'; --修改所有IP都能登录 grant all on *.* to 'root'@'%'; --更新权限 flush privileges;
修改mysql 配置文件
--先停止mysql 服务 service mysql stop --修改配置文件(注意是mysqld.cnf文件,不是mysql.cnf文件,因为这下面有这两个文件,容易搞错) vim /etc/mysql/mysql.conf.d/mysqld.cnf
--找到 bind-address = 127.0.0.1 注释掉
# bind-address = 127.0.0.1
--去掉这两个的注释,当然可以根据自己的想法改
port = 3306
datadir = /var/lib/mysql