Linux / ubantu 安装 MySql 数据库 Navicat远程访问

1.切换root权限: 输入 sudo su 回车,输入root帐号密码
2.安装MySql
说明:默认情况下,只有最新版本的MySql包含在APT软件包存储库中,安装最新版本的MySql只需更新服务器上的包索引,并安装默认的包 apt-get。

apt-get update
apt-get install mysql-server

安装过程中会弹出创建超级管理员的用户名和密码提示,选择你自己常用的且容易记住的用户名密码即刻
3.配置MySql
因为是全新安装,您需要运行附带的安全脚本。这会更改一些不太安全的默认选项,例如远程 root 登录和示例用户。在旧版本的 MySQL 上,您需要手动初始化数据目录,但 Mysql 5.7 已经自动完成了。
运行安全脚本。

sudo mysql_secure_installation

之后会有一下提示,选择自己合适的
root@localhost:/# sudo mysql_secure_installation (修改root密码)
Securing the MySQL server deployment.
Enter password for user root:
VALIDATE PASSWORD PLUGIN 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 plugin?
Press y|Y for Yes, any other key for No: y(是否安装密码安全插件,开发环境可以选n)
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: (安全模式0低,1中等,2强)
Invalid option provided.
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Using existing password for root.
Estimated strength of the password: 25
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n
… skipping.
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(是否禁止root远程登录)
… 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数据库安装完成!
4.检测MySql服务

查看进程:ps -ef|grep mysql
启动服务:service mysql start
停止服务:service mysql stop
重启服务:service mysql restart

5.设置MySQL远程访问权限

sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf (编辑此配置文件)
#bind-address = 127.0.0.1 (注释本地IP)
bind-address = 0.0.0.0 (或者 重新 添加一行)

退出编辑模式保存文件
进入MySql 命令行
mysql -u root -p 回车,输入密码
授权root用户访问权限,并刷新权限,此处的root可用其它MySQL用户替换,pwd部分需替换为该用户对应的密码
grant all privileges on *.* to root@"%" identified by "pwd" with grant option;(分配权限)
flush privileges;(刷新权限)
exit;(退出)
重启MySql服务
service mysql restart
6.查询防火墙状态
sudo ufw status
关闭防火墙
sudo ufw disable
开启 防火墙
sudo ufw enable
7.卸载MySql数据库

sudo apt purge mysql-*
sudo rm -rf /etc/mysql/ /var/lib/mysql
sudo apt autoremove
sudo apt autoclean

你可能感兴趣的:(数据库)