1、执行 sudo apt install mysql-server
安装mysql-server。本文mysql-server的版本是8.0
安装过程中会提示设置root密码,按照提示输入即可
2、验证安装 mysql -u root -p
3、修改root用户的远程访问权限 update user set host='%' where user='root';
4、刷新权限表FLUSH PRIVILEGES;
5、重启mysql 服务
错误记录
mysql8.0如何重置root密码
- 关闭mysql服务,使用
skip-grant-tables
跳过权限验证
vi /etc/mysql/mysql.conf.d/mysqld.cnf
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# The MySQL Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
log-error = /var/log/mysql/error.log
skip-grant-tables
重启mysql服务
sudo service mysql start
进入mysql,刷新权限表
flush privileges;
-
查看
root
用户和密码字段先将密码滞空use mysql;
查看用户列表
select host, user, authentication_string, plugin from user;
将旧密码制空
update user set authentication_string='' where user='root';
-
删除
skip-grant-tables
限制,重启mysql
服务,重连mysql
,并重置密码use mysql;
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';