怎么配置mysql数据库配置文件

怎么配置mysql数据库配置文件,第1张

一、mysql_install_db说明

当MySQL的系统库(mysql系统库谨灶)发生故障或需要新加一个mysql实例时,需要初始化mysql数据库。

需要使用的镇圆命令:/usr/local/mysql/bin/mysql_install_db

#/usr/local/mysql/bin/mysql_install_db --help 可以查看帮助信息如下

Usage: /usr/local/mysql/bin/mysql_install_db [OPTIONS]

--basedir=path The path to the MySQL installation directory.

--cross-bootstrapFor 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.

--rpmFor 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=pathFor 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.

All other options are passed to the mysqld program

除了支持以上的参数,还支持mysqld的参数。

二、举例:

本祥旅扮文以新加一个mysql实例为例。例如服务器上已经安装了3306端口的mysql服务,需要再启一个3308端口的mysql服务。

假设mysql安装在/usr/local/mysql路径下,找一个磁盘空间剩余比较大的盘,如/data1,把3308端口的mysql的数据保存在/data1下

#mkdir /data1/mysql_3308

#mkdir /data1/mysql_3308/data

#chown -R mysql:mysql /data1/mysql_3308

复制一个mysql配置文件my.cnf到/data1/mysql_3308目录下

#vi /data1/mysql_3308/my.cnf

修改配置文件,将端口和相关目录的都改为新的设置,如下:

[client]

character-set-server = utf8

port= 3308

socket = /tmp/mysql_3308.sock

[mysqld]

user= mysql

port= 3308

socket = /tmp/mysql_3308.sock

basedir = /usr/local/mysql

datadir = /data1/mysql_3308/data

log-error = /data1/mysql_3308/mysql_error.log

pid-file = /data1/mysql_3308/mysql.pid

......其他略

确保配置文件无误。

运行下面命令进行数据库的初始化:

#/usr/local/mysql/bin/mysql_install_db --defaults-file=/data1/mysql_3308/my.cnf --datadir=/data1/mysql_3308/data

完成后新的3308数据库就初始化好了,如果有报错,则按照报错的提示查看报错日志,一般情况下都是my.cnf配置文件的问题,修正后即可。

三、启动新mysql

启动3308端口的mysql服务

#/usr/local/mysql/bin/mysqld_safe --defaults-file=/data1/mysql_3309/my.cnf &

检查是否启动

#ps aux|grep mysql

如果有3308字样说明已经启动成功

可将启动命令加入/etc/rc.local随服务器启动

新加的mysql没有设置root密码,可以通过下面命令设置root密码:

#/usr/local/mysql/bin/mysqladmin -S /tmp/mysql_3308.sock -u root password 'new-password'

my.cnf 这个配置文件如果为空或不存在的时候,mysql采用默认配置运行,解决方法如下:

1、首先通过SSH登陆Linux服务器,登陆后,命令行键入“Nano /etc/my.cnf”敏型即通过Nano浏览my.cnf文冲清件,桥判猜如图所示。

2、通过光标移动定位需要修改的参数行,想要设置max_connections参数,则下面的参数行max_connections=100,如图所示。

3、然后把max_connections的参数设置成想要修改的数值,例如110,如图所示。

4、然后键入Ctrl+O写入writeout并保存修改。

5、最后键盘上键入Ctrl+X退出Nano,就设置完成了。

1、在我们的电脑上面找到mysql的安装路径,点击进去。

2、进去之后哪清可以看到my.ini在mysql安装路径的根目录,这是旁迅其中一种情况。

3、另外一种情况是我们在mysql安装目录找不到,看到了my-default.ini文件,这时my.ini在“C:\ProgramData\MySQL\MySQL Server 5.6”目录下面,我们首先需要找到ProgramData文件夹,这是一个隐藏文件,需要隐藏文件可见才行,或者可以直接检索。

4、我们可以看到在“C:\ProgramData\MySQL\MySQL Server 5.6”目录下面找到了my.ini文李启前件。

5、我们右键my.ini文件,选择打开方式,可以通过记事本和其他文本编辑器打开。

6、我们可以看到my.ini的文件打开了。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/12258066.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存