一、安装器和网络工具更新
sudo apt-get update
sudo apt-get install net-tool
二、MySQL安装步骤如下
1.使用root账号
sudo apt-get install mysql-server
2.使用如下命令查询是否安装成功
sudo netstat -tap | grep mysql
3.重启mysql
方法1
sudo service mysql restart
方法2
sudo /etc/init.d/mysql restart
三、查看MySQL版本
方法1
用shell命令直接查看
mysql -V
方法2
用shell命令直接查看
mysql --help | grep Distrib
方法3
先用shell命令登陆mysql
sudo mysql
然后用mysql命令查看版本
mysql> select version();
mysql> status
四、设置mysql的root账户密码
mysql -u root -p
mysql> update mysql.user set authentication_string=password('访问数据库的密码') where user = 'root';
mysql> flush privileges;
五、添加用户访问数据库的权限
以xyz账户为例添加数据库hello的访问权限
mysql> create user xyz;
mysql> update mysql.user set authentication_string=password('访问数据库的密码') where user = 'xyz';
mysql> update mysql.user set host=localhost where user = 'xyz';
mysql> grant all privilages on hello.* to 'xyz'@'localhost';
mysql> flush privileges;
六、设置MySQL远程访问的权限
1.编辑mysql的启动配置文件
sudo gedit /etc/mysql/mysql.conf.d/mysqld.cnf
加前缀#注释掉bind-address = 127.0.0.1
保存并退出gedit
2.授权远程任意IP地址可以访问数据库
mysql> grant all privilages on hello.* to xyz@"%" identified by "访问数据库的密码" with grant option;
mysql> flush privileges;
mysql> quit
sudo ufw enable
sudo ufw default deny
sudo ufw allow 3306
3.重启mysql
sudo /etc/init.d/mysql restart
sudo apt-get update
sudo apt-get install net-tool
二、MySQL安装步骤如下
1.使用root账号
sudo apt-get install mysql-server
2.使用如下命令查询是否安装成功
sudo netstat -tap | grep mysql
3.重启mysql
方法1
sudo service mysql restart
方法2
sudo /etc/init.d/mysql restart
三、查看MySQL版本
方法1
用shell命令直接查看
mysql -V
方法2
用shell命令直接查看
mysql --help | grep Distrib
方法3
先用shell命令登陆mysql
sudo mysql
然后用mysql命令查看版本
mysql> select version();
mysql> status
四、设置mysql的root账户密码
mysql -u root -p
mysql> update mysql.user set authentication_string=password('访问数据库的密码') where user = 'root';
mysql> flush privileges;
五、添加用户访问数据库的权限
以xyz账户为例添加数据库hello的访问权限
mysql> create user xyz;
mysql> update mysql.user set authentication_string=password('访问数据库的密码') where user = 'xyz';
mysql> update mysql.user set host=localhost where user = 'xyz';
mysql> grant all privilages on hello.* to 'xyz'@'localhost';
mysql> flush privileges;
六、设置MySQL远程访问的权限
1.编辑mysql的启动配置文件
sudo gedit /etc/mysql/mysql.conf.d/mysqld.cnf
加前缀#注释掉bind-address = 127.0.0.1
保存并退出gedit
2.授权远程任意IP地址可以访问数据库
mysql> grant all privilages on hello.* to xyz@"%" identified by "访问数据库的密码" with grant option;
mysql> flush privileges;
mysql> quit
sudo ufw enable
sudo ufw default deny
sudo ufw allow 3306
3.重启mysql
sudo /etc/init.d/mysql restart