ubuntu在安装MySQL常见问题和mysql_secure_installation向导记录详解

ubutu 安装 mysql
sudo apt update
sudo apt install mysql-server

sudo mysql_secure_installation 请根据需要进行设置,对后续使用有影响(步骤记录在下文)

systemctl status mysql.service 查看mysql安装后的服务状态

mysql安装常见问题

需注意:
	a.开启 **mysql远程**
		修改mysql的配置文件(通常在 /etc/mysql下 /etc/mysql/mysql.conf.d/mysqld.cnf)
        bind-address = 127.0.0.1 修改为(注释掉)
        #bind-address = 127.0.0.1

 	service mysql restart 重启
    b.如果报错 **错误码1130**
        sudo mysql -uroot -p
        #输入安装时设置的密码(注意提示输入管理员还是mysql的密码)
        use mysql;
        select 'host' from user where user='root';
        update user set 'host'='%' where user='root';
        如果报错则执行: (update user set `host`='%' where user='root';)
        flush privileges;
        exit;

    c.如果报错 **错误码1045**
        需要更改密码,重新进入mysql

        use mysql;
        update user set password=password("123456") where user="root";
        #设置密码,密码强度根据安装时设置的强度进行设置
        flush privileges;
        exit;
        
     d.如果报错 **错误码1698**
     	查看一下user表,错误的起因就是在这里, root的plugin被修改成了auth_socket,用密码登陆的plugin应该是mysql_native_password。(也就是应该把这个字段改成用密码登陆,而不是用socket!)
     	sudo mysql -uroot -p
        #输入安装时设置的密码(注意提示输入管理员还是mysql的密码)

     	mysql> select user, plugin from mysql.user;
     	| user             | plugin                |
        +------------------+-----------------------+
        | root             | auth_socket 
        
        确认 root的是 auth_socket 则修改为
        mysql>  update mysql.user set authentication_string=PASSWORD('password'), plugin='mysql_native_password' where user='root';
        mysql> flush privileges;
        mysql> exit ;
操作完后,执行重新启动mysql服务
service mysql restart

mysql_secure_installation 操作步骤记录说明
[root@server1 ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL

SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we’ll need the current

password for the root user. If you’ve just installed MySQL, and

you haven’t set the root password yet, the password will be blank,

so you should just press enter here.

Enter current password for root (enter for none):<–初次运行直接回车

OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MySQL

root user without the proper authorisation.

Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车

New password: <– 设置root用户的密码

Re-enter new password: <– 再输入一次你设置的密码

Password updated successfully!

Reloading privilege tables…

… Success!

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? [Y/n] <– 是否删除匿名用户,生产环境建议删除,所以直接回车

… 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? [Y/n] <–是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止(根据个人需求)

… 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? [Y/n] <– 是否删除test数据库,直接回车(根据个人需求)

  • 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? [Y/n] <– 是否重新加载权限表,直接回车

… Success!

Cleaning up…

All done! If you’ve completed all of the above steps, your MySQL

installation should now be secure.

Thanks for using MySQL!

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