本地(linux环境,deepin 15.9,基于debain)安装个mysql环境,结果遇到了不少问题,记录下。
安装
sudo apt-get install mysql-server-5.7 mysql-client-5.7
安装之后,可以直接启动起来:
sudo service mysql start
查看mysql是否启动成功:
ps -ef | grep mysql
结果如下:
mysql 9452 1 0 15:59 ? 00:00:09 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid
alanjin 29079 7819 0 20:45 pts/0 00:00:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn mysql
可以看到,用户mysql下pid为9452的进程,即为mysql的运行进程。
密码验证设置
默认情况下,root用户的密码为空,不过直接 mysql -u root 无法登录,因为没有权限,需要加上sudo
sudo mysql -u root
登录之后,执行以下命令:
use mysql;
mysql> SELECT user, host, plugin FROM user;
+------------------+-----------+-----------------------+
| user | host | plugin |
+------------------+-----------+-----------------------+
| root | localhost | auth_socket |
| mysql.session | localhost | mysql_native_password |
| mysql.sys | localhost | mysql_native_password |
| debian-sys-maint | localhost | mysql_native_password |
+------------------+-----------+-----------------------+
4 rows in set (0.00 sec)
可以看到,root默认的密码验证方式是auth_socket,这个是UNIX auth_socket_plugin 的用户认证方式。如果希望正常使用,还是要改成mysql_native_password
mysql> update user set plugin='mysql_native_password' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
密码设置
上面操作结束后,退出mysql,执行以下操作
sudo mysql_secure_installation
这个命令会引导你设置root的密码,以及一些其他操作,如下:
➜ ~ sudo mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Please set the password for root here.
# 设置密码,但是这里可以看到,由于启用了validate_password,所以如果密码复杂度不够,会如下所示的提示密码设置不成功
New password:
Re-enter new password:
Estimated strength of the password: 25
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
... Failed! Error: Your password does not satisfy the current policy requirements
#密码设置成Root@123这种有大小写、特殊字符、数字的内容,就通过了
New password:
Re-enter new password:
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
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.
# 是否禁用root用户远程登录?这里不禁用,当然如果你希望禁用,并且创建别的用户远程登录,这里可以选择y
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.
# 是否删除test数据库,这里删除即可,不然留着也没什么用
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.
# 是否刷新权限?,这里选择y,然后会生效
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
All done!
进入mysql
上面一堆操作之后,就可以不使用sudo登录mysql了,也可以直接远程客户端连接登录。
mysql -u root -pRoot@123
网友评论