centos mysql 怎么初始化

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos mysql 怎么初始化相关的知识,希望对你有一定的参考价值。

参考技术A 使用的命令:mysql_install_db,用于初始化mysql的数据库,生成元数据。
若不加任何参数,则该命令按照/etc/my.cnf文件配置执行初始化工作,否则可参照如下帮助手动执行参数。
$ mysql_install_db --help 可以查看帮助信息如下
Usage: /usr/local/mysql/bin/mysql_install_db [OPTIONS]
--basedir=path The path to the MySQL installation directory.
--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.
--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.
--ldata=path The path to the MySQL data directory.
--rpm For internal use. This option is used by RPM files
during the MySQL installation process.
--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 For internal use. The directory under which
mysql_install_db looks for support files such as the
error message file and the file for popoulating the
help 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.

CentOs7下安装mysql5.7.14,初始化完成登录mysql提示密码过期

解决方法:1. 使用mysql的绝对路径登录,一般mysql的安装路径为/usr/local/mysql,则使用如下命令

/usr/local/mysql/bin/mysql -uroot -p‘password‘

2.cp /usr/local/mysql/bin/mysql /usr/bin/

mysql -uroot -p‘password‘


原因解释:安装CentOs的时候,默认安装了mysql,并且版本与自己安装的mysql版本不一致,直接使用mysql -uroot -p‘password‘连接,默认调用的是系统安装的mysql版本,所以会提示密码过期。可以通过指定mysql的绝对路径或者拷贝新安装的mysql客户端到系统路径下解决此问题。

以上是关于centos mysql 怎么初始化的主要内容,如果未能解决你的问题,请参考以下文章

centos自带MYSQL的初始化

Centos7 初始化MySQL5.7数据库

CentOs7下安装mysql5.7.14,初始化完成登录mysql提示密码过期

centos7 安装MySQL7 并更改初始化密码

centos7.2 安装mysql8.0.11 并自动初始化root密码

MySQL数据库二进制安装初始化报错