How to separate /etc/my.cnf for different mysql versions - mysql

I want to be able to have different mysql/percona servers installed on same server.
However only one of them will be active until I decide to deactivate it and activate another.
Is there easy way to put /etc/my.cnf inside mysql data directory instead of /etc?
PHP using similar approach - ini file is inside php directory and /etc/php.ini is a symlink.
I am thinking about global /etc/my.cnf with single like !!includedir /xxxx/yyyy/$version.
Is this possible?

you can installed different version on same node with different data directive. To run same,you need to run mysql server with path of config file like below:
FULL_PATH/mysqld_safe --defaults-file=FULL_PATH/my.cnf &

Related

I can't find the file "my.cnf" or "my.ini"

I installed version 8 of MySQL and I can't find the configuration file
I was reading and everyone says that it is inside the "MySQL Server x.0" folder, but in my case it does not appear, neither inside the "etc" or "bin" folder
How I found mine was like this;
mysqld --help --verbose | grep my.cnf
I guess you are on Windows because of the "MySQL Server x.0" folder name (on Mac & Linux, this folder name does not contain spaces by default).
No configuration file is created after a standard installation. You may create one if you have the need to specify any options. Otherwise every option has a default setting built into the MySQL Server.
On Windows, the MySQL Server searches several locations for the configuration file, so you can put the file in any of those locations.
See documentation for a list of the locations the server searches for the configuration file on Windows:
https://dev.mysql.com/doc/refman/8.0/en/windows-create-option-file.html
https://dev.mysql.com/doc/refman/8.0/en/option-files.html
Remember that after you edit the configuration file, you need to restart the MySQL Server. It reads the configuration options only when the server starts.
On Windows my.ini file will be auto generated when you install MySQL server. It will be located in a hidden directory ProgramData.
C:\ProgramData\MySQL\MySQL Server 8.0
In order to view these files you may need to show hidden items. To do that
Open file explorer > View > Tick Hidden Items

MySQL binary log location Windows 2008 Server

I'm running a Windows 2008 Server with IIS, PHP and MySQL. MySQL is installed as a service. There's software on the server that uses a database that I need good backups of, including transaction logging. I've turned on Binary Logging via setting log-bin= and expire_logs_days= in the my.ini file. This saves those logs in the MySQL data folder on that drive. If I lose the drive, I lose my logs and they've done me no good as a backup.
I've found all kinds of advice for relocating these logs on a Linux box, but trying to use the same idea of including a path in the log-bin statement is not working. I've tried "flipping" the slashes, adding quotes and the common other attempts when "translating" Linux to Windows.
I created a mapped drive to the external location to make this easier, and I've tried using \server\folder path statements as well as z:\ path statements.
Any help would be greatly appreciated.
If you made your changes in the [mysqld] section in the my.ini file then you should be good. The correct path naming convention, should look something like this log-bin="C:/yourfilepathname/logs". Since you are still experiencing issues, Please check to make sure that mysql has permission to write to the directory that you are specify the logs files to be written to.
Another way you can check if this is the issue, go to your .err log file when you try to stop and start mysql server it will tell you something along the lines of not having permission to write to that directory.
Also, I would note that log bin files in it of themselves are not a backup. You need to be taking mysqldumps or snapshots of the entire directory from your server, preferably from a slave of your master production server.
You are missing a trailing slash.
Here is what's in my my.ini (I'm using MariaDB 10.1, but I believe this will work for you also):
[mysqld]
datadir=D:/mysql-data
log-bin=E:/mysql-bin/
When I left out the trailing slash in the log-bin setting, I also got the same error in logs, and the service failed to start. After adding the slash, no errors, and the service started successfully.
I now see files getting created in E:\mysql-bin, such as .index, .000001.
make sure you are ending with filename. see below.
log-bin=C:/Program Files/MySQL/MySQL Server 5.6/data/bin.log
Actually it's due to using the normal windows backslashes. Instead of z:\ use z:/ (forward slash). Also if you don't end with a forward slash then it will use the last part as the file name. Exp:
z:/bin-logs/ (this will have files named .index and .000001)
z:/bin-logs/log (this will have files named log.index and log.000001)

Created a mysql database but can't seem to find it anywhere

I just cloned a repo from github and bundle installed everything and created a mysql db via rake db:create. I migrated the database and everything....however, I have no idea where it is located? Usually when I use sqlite, it's in the db/ folder...but this database is not. where can I find it?
Look in your MySQL config file. Usually it's called my.cnf. Where to find this config on your system, we can't say :-)
Look for datadir in a config file
[mysqld]
datadir=/var/lib/mysql/
MySQL works a bit differently than sqlite. Whereas sqlite writes a database directly to a file (in your db/ directory in the case of rails), MySQL writes it to a server (usually located on the same machine as your application, but not always). I would be surprised if an app you cloned off of github let you create a mysql database right off the bat. You need to set up a mysql server and set a password for it. If you're running Ubuntu -- as I am -- these are some good instructions. Then you need to configure your config/database.yml file accordingly.

changing default my.cnf path in mysql

I am having two mysql instances on same machine. The installations are on /usr/loca/mysql1 and /usr/local/mysql2.
I m having separate my.cnf files located in /etc/mysql1 and /etc/mysql2. I installed the first instance of my sql using source distribution and with the --prefix=/usr/local/mysql1 option. The second one i got from copying and pastinf the same directory to /usr/local/mysql2.
When i start the mysql daemon on /usr.local/mysql/libexec it reads the my.cnf file in /etc/mysql1. And if i start the mysql daemon in /usr/local/mysql2 it reads the same my.cnf file. I have separate port numbers and .sock files defined in the .cnf file in those 2 locations.
I can read the my.cnf file in the second location by using --defaults-file=/etc/mysql2/my.cnf option on mysqld startup. I do not need to enter this each and every time i start the daemon.
If i am going to have more instances how can i point the correct my.cnf file to read to each and every mysql daemon. What is the retionale behind mysqld links with the my.cnf file.
how can i predefine the location of my.cnf file for each instance.
As you've already discovered, MySQL has a compiled-in search location for its configuration file. Although you could recompile yourself, changing this, you've also discovered the --defaults-file option to mysqld, which instructs it to use an entirely different configuration path. Coupled with --data-dir, this means you can start multiple instances of MySQL bound to different ports (and addresses, if liked) and working with entirely separate sets of data, while working off the same binaries and libraries.
Traditionally, most operating system distributions will bundle a single init script for starting the "default" instance of MySQL; that is, the one installed in the "usual" location, and with the standard configuration path. Although this is to cater for the commonest case, what you're after is a bit different, so you'll need to create separate scripts to launch the separate instances.
If you're planning on deploying a lot of MySQL instances on the same machine (and I'd have to ask why), then you may want to write a custom init script which has some way of "discovering" each of these (perhaps by inspecting some directory containing a "common" layout), and then loops over them, starting each one up. Of course, the same init script then needs to be capable of locating and properly shutting down each one.
I think the only sure way is to compile from source with the prefix option. Either that, or create a bash script that starts mysql2 with the --defaults-file option and then use that to start it instead.
However, "creating" another installation the way you did isn't good. When you compile a package, the PREFIX is hard-coded into the executable. So whenever it looks for a resource, it starts from that prefix, unless told not to with command line options.
So, if I were you, I'd just recompile from source with a new prefix.

MySql portable version

anyone know a portable version of mysql?
I know xampp but it comes with PHP and Apache together
anyone know how to isolate the mysql?
You can download the MySQL Essentials version and make a few small changes to directories in the my.ini file to use relative paths instead of absolute paths. Then you can run the server directly without having to install or use a Windows service.
Download a MySQL .zip file (instead of an .msi, though you could get the .msi and use 7Zip or Orca to extract the files from it).
Extract the files. At a minimum you need the bin and share directories (actually, in bin, you really only need mysqld.exe as the absolute minimum to run a server).
Edit my.ini to change the basedir and datadir paths to something relative. For example:
basedir=".."
datadir="/MySQLdb"
If you do not have an existing database, then create one:
mysqld --bootstrap
Run the server (you may need to use the --skip-grant-tables switch to get it running until you have set up your MySQL user):
mysqld
To avoid the server being run in the current command-prompt, you can use the following to have it run in its own console which should disappear once it is running:
start mysqld
If you get errors, delete the log files (e.g., logs\ib_logfile*) and run it again.
I think not, without counting on XAMPP. You don't have to use PHP or Apache anyway, just run the mysql from the .exe's
Created a portable configuration at https://sourceforge.net/projects/mysql-server-portable/
You should put your my.cnf or my.ini in a different directory than your data directory.
You will then need to initialize your portable version,
"\mysql-5.7.30-winx64\bin\mysqld" --defaults-file="\mysql-5.7.30-winx64\config\my.ini" --standalone --explicit_defaults_for_timestamp --initialize
then you can start your portable version,
"\mysql-5.7.30-winx64\bin\mysqld" --defaults-file="\mysql-5.7.30-winx64\config\my.ini" --standalone --explicit_defaults_for_timestamp