MySql教程

mysql_install_db 一次修复密码

本文主要是介绍mysql_install_db 一次修复密码,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

我用mysql 社区版进行的安装,在linux centos 操作系统下, yum install 方式
系统默认安装时没有密码的,需要你及时设置,但是我操作多次后,并没有修改密码,启动和关闭多次以后就登录不上了。
只要重新安装授权表即可,注意指定data目录。

查看下原来的目录下的权限情况

 [root@fp-web-118 bin]# ll /var/lib/mysql
total 110604
-rw-rw---- 1 mysql mysql 56 Jan 30 20:14 auto.cnf
-rw-rw---- 1 mysql mysql 12582912 Feb 1 20:44 ibdata1
-rw-rw---- 1 mysql mysql 50331648 Feb 1 20:44 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 Jan 30 20:14 ib_logfile1
drwx------ 2 mysql mysql 4096 Jan 30 20:14 mysql
srwxrwxrwx 1 mysql mysql 0 Feb 1 20:44 mysql.sock
drwx------ 2 root root 4096 Feb 1 20:38 performance_schema

重新安装

[root@fp-web-118 bin]# mysql_install_db --datadir=/var/lib/mysql

执行过程,关键部分我留下来做了翻译------

Installing MySQL system tables...2022-02-01 20:38:29 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-02-01 20:38:29 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2022-02-01 20:38:29 0 [Note] /usr/sbin/mysqld (mysqld 5.6.51) starting as process 75620 ...
2022-02-01 20:38:29 75620 [Note] InnoDB: Using atomics to ref count buffer pool pages
2022-02-01 20:38:29 75620 [Note] InnoDB: The InnoDB memory heap is disabled
2022-02-01 20:38:29 75620 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
..... ##其他部分不必要信息我删除掉了,留下仅有的一些提示
/usr/bin/mysqladmin -u root password 'jinzs'
/usr/bin/mysqladmin -u root -h fp-web-118 password 'jinzs'  

你可以运行 /usr/bin/mysql_secure_installation

他会给你一些选项去删除test数据库或者是匿名的用户,通过默认方式安装得时候

cd /usr ; /usr/bin/mysqld_safe &   ##你可以测试你的mysql,用这个脚本 mysql-test-run.pl

cd mysql-test ; perl mysql-test-run.pl  ##你可以测试你的mysql,用这个脚本 mysql-test-run.pl


WARNING: 默认是 /etc/my.cnf 会被读取,如果你要用别的配置文件,可以使用 --defaults-file参数设置

 

设置密码

 [root@fp-web-118 bin]# mysqladmin -u root -h fp-web-118 password 'jinzs'

登录

 

[root@fp-web-118 bin]# mysql -u root -h fp-web-118 -pjinzs

Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.51 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

 

我们看看 mysql_install_db得作用
1、当MySQL的系统库(mysql系统库)发生故障,需要初始化mysql数据库。
2、重新初始化授权表
3、在一台机器上安装mysql实例。

mysqladmin的相关命令:
[root@fp-web-118 bin]# mysql_install_db --help
Usage: /usr/bin/mysql_install_db [OPTIONS]
--basedir=path The path to the MySQL installation directory.
--builddir=path If using --srcdir with out-of-directory builds, you
will need to set this to the location of the build
directory where built files reside.
--cross-bootstrap For internal use. Used when building the MySQL system
tables on a different host than the target.
--datadir=path The path to the MySQL data directory.
If missing, the directory will be created, but its
parent directory must already exist and be writable.
--defaults-extra-file=name
Read this file after the global files are read.
--defaults-file=name Only read default options from the given file name.
--force Causes mysql_install_db to run even if DNS does not
work. In that case, grant table entries that
normally use hostnames will use IP addresses.
--help Display this help and exit.
--ldata=path The path to the MySQL data directory. Same as --datadir.
--no-defaults Don't read default options from any option file.
--keep-my-cnf Don't try to create my.cnf based on template.
Useful for systems with working, updated my.cnf.
Deprecated, will be removed in future version.
--random-passwords Create and set a random password for all root accounts
and set the "password expired" flag,
also remove the anonymous accounts.
--rpm For internal use. This option is used by RPM files
during the MySQL installation process.
Implies --keep-my-cnf option.
--skip-name-resolve Use IP addresses rather than hostnames when creating
grant table entries. This option can be useful if
your DNS does not work.
--srcdir=path The path to the MySQL source directory. This option
uses the compiled binaries and support files within the
source tree, useful for if you don't want to install
MySQL yet and just want to create the system tables.
--user=user_name The login username to use for running mysqld. Files
and directories created by mysqld will be owned by this
user. You must be root to use this option. By default
mysqld runs using your current login name and files and
directories that it creates will be owned by you.
Any other options are passed to the mysqld program.

 

这篇关于mysql_install_db 一次修复密码的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!