1.安装 MySQL 5.7
安装 MySQL 运行命令:
1. apt-get -y install mysql-server mysql-client
第一步报错在命令前加sudo 然后提示密码;解决问题。
然后提示进程占用问题
原因:apt-get被ubuntu软件中心占用,终端输入命令:ps -e,可以查看到apt-get进程
总得来说系统中apt-get只能被一个占用。
解决方案
强制解锁,命令
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock
2.你会被要求提供MySQL的root用户密码 :
New password for the MySQL “root” user: <– yourrootsqlpassword
Repeat password for the MySQL “root” user: <– yourrootsqlpassword
3.执行命令
root@server1:~# mysql_secure_installation
你会问这些问题:
保护MySQL服务器部署。
Enter password for user root: <– Enter the MySQL root password
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: <– Press y if you want this function or press Enter otherwise.
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : <– Press enter
… 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) : <– y
Success.
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) : <– y
Success.
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) : <– y
– Dropping test database…
Success.
– Removing privileges on test database…
Success.
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 is secured now.
4.mysql初始化完毕后,我们现在来创建zabbix数据库及其用户,使用如下命令:
mysql -uroot -pzabbix’ -e “create database zabbix default character set utf8 collate utf8_bin;”
zabbix’ -e “grant all on zabbix.* to ‘zabbix’@’%’ identified by ‘zabbix’;”
mysql -uroot -p
第二条语句有误,查资料后解决:
但因为我建数据库时手贱,把密码等级选了第二个,应该选low
通过 SET GLOBAL validate_password_policy='LOW';
命令,降低安全等级后,就可以直接使用,限制是必须8个字符以上;
现在来测试刚刚创建的zabbix用户,是否可以连接mysql数据库,如下:
mysql -uzabbix -pzabbix
mysql> show databases;
——————–+
| Database |
+——————–+
| information_schema |
| mysql |
| performance_schema |
| sys |
| zabbix |
+——————–+
5 rows in set (0.06 sec)
通过上图,我们可以很明显的看出zabbix用户是可以正常连接数据库的。