I'm just curious as I am beginning to learn PHP and MySQL, as to where the database and other files of MySQL reside on the hard drive. I have installed WAMP on a Windows XP SP2 platform.
Explore variables from the output of following command:
mysql> show variables like '%dir%';
Data directories for mysql database :
Generally,
Windows wamp setup : mysql/data
Linux (Ubuntu) : /var/lib/mysql
Configured Location: [ my.cnf configures it as datadir ]
Linux :
$ cat /etc/mysql/my.cnf | grep 'datadir'
Windows :
Open mysql/my.cnf (search for `datadir` )
From mysql prompt : ( mysql> ) [ PREFERRED WAY ]
mysql> show variable like 'datadir';
I suppose that covers pretty much all cases.
Usually in the /mysql/data directory of your WAMP installation. You'll recognize the location because every database has a folder with the same name there.
You can change the location of the data directory using the datadir setting in my.cnf. It is often moved elsewhere to ensure the data there gets backed up regularly.
I am not sure about WAMP, but if you install MySQL manually it should reside somewhere along the lines of this path:
C:\Program Files\MySQL\MySQL Server 5.1
Use the following to find the data directory using SQL console:
show variables like 'datadir'
If your on linux you can use:
sudo find / mysql | grep mysql
On Ubuntu it stores its database files in /var/lib/mysql
wamp/bin/mysql/mysqlx.x.x/data
Related
I installed mysql 8.0. During the process of install, it will guide you to create a server that is registered as window service. For example, by default it will put server related file on the (base)path "C:\ProgramData\MySQL\MySQL Server 8.0" using default port 3306. What if I want to create another server?What should I do? Maybe using mysqld --initialize?
Well make sure you have installed a running and properly configured MySQL Server and Instance. If so, copy the data directory of your running MySQL Instance (Server) in a second folder.
Existing Folder: C:\ProgramData\MySQL\MySQL Server 5.7
New Folder (for example): C:\ProgramData\MySQL\MySQL second Server 5.7
NEXT: Create 2 Option-Files (a ka .txt files, you save as my-opts[Optummber.cnf)]. You may create one file named C:\ProgramData\MySQL\my-opts1.cnf that looks like this:
File 1 Content:
[mysqld]
datadir = C:\ProgramData\MySQL\MySQL Server 5.7\mydata1
port = 3307
Create a second file named C:\ProgramData\MySQL\my-opts2.cnf that looks like this:
[mysqld]
datadir = C:\ProgramData\MySQL\MySQL second Server 5.7\mydata2
port = 3308
NEXT: Use the --defaults-file option to start each server, runnig on its own option file:
C:\> C:\ProgramData\MySQL\bin\mysqld --defaults-file=C:\ProgramData\MySQL\my-opts1.cnf
C:\> C:\ProgramData\MySQL\bin\mysqld --defaults-file=C:\ProgramData\MySQL\my-opts2.cnf
Note: Each will start visibly, with a new prompt until the server exits later), so you will need to issue those two commands in separate console windows.
To shut down the servers, connect to each using the appropriate port number:
C:\> C:\ProgramData\MySQL\bin\mysqladmin --port=3307 --host=127.0.0.1 --user=root --password shutdown
C:\> C:\ProgramData\MySQL\bin\mysqladmin --port=3308 --host=127.0.0.1 --user=root --password shutdown
Servers configured as just described permit clients to connect over TCP/IP. - If you want to do so, please follow the guide on: https://dev.mysql.com/doc/refman/8.0/en/multiple-windows-command-line-servers.html
Note: I wrote the commands in here based on https://dev.mysql.com/doc/refman/8.0/en/multiple-windows-command-line-servers.html. Please modify them according to your file System and MySQL Configuration. I don't take any warranty for them. If the used filepaths seem to complicated for you, please change them to the eased up versions in the linked description. Setting up mySQL Instances might be a challenging process, just do so, if you can handle it.
I am trying to enable slow_query_log on mysql, but I could not find it on my mac.
I read in MySQL 5.7 Documentation that"
By default, the server writes files for all enabled logs in the data directory.
When I write show variables like '%slow_query%'; in mysql shell, I see the following:
but I can't see McBook-Pro-6-slow.log in the data directory. Here is all I can see in the data directory:
Could someone let me know why I can't see the slow log file?
In order to enable the slow_query_log, I've read here that I should add slow-query-log=1 to my.cnf. Here, my problem is that I am not sure where is mysql config file on my Mac. I've found a my-default.cnf in usr/local/mysql/support-files/ and another my.cnf file in /etc. Which one should I modify??
Thanks,
Refer to this Stackoverflow question MySQL 'my.cnf' location? which pertains to Mac OS. As you can see the permutations of locations are numerous usually compounded by different distros and MAMP XAMP WAMP bundles and Home Brew. It is not uncommon to have 2 mysql daemons on a box and not even know it.
Which is why in comments I suggested looking at the output of select ##basedir for the location of the my.ini (Windows) or my.cnf (Linux/Mac). That is not to suggest a configuration file is going to be there, but that is where it should be if one were to exist. Without it, baked-in default values are used. Often there is a stub, a suggested file, named differently (like my-default), awaiting your tweaks and a rename or copy to the appropriate file name of my.ini or my.cnf.
There is also a system variable named slow_query_log_file and its value visible if set thru SELECT ##slow_query_log_file;. For me right now it has a value of GUYSMILEY-slow.log because I did not set it in my ini (Windows) and it defaults to computername+"-slow.log".
That is the filename without the path. Where the file actually is written to is in the datadir seen with the output of select ##datadir;.
On my system this means (via ##basedir)
C:\Program Files\MySQL\MySQL Server 5.6\my.ini
would have a setting that ends up in a slowlog file written to in this absolute path (helped by ##datadir):
C:\ProgramData\MySQL\MySQL Server 5.6\data\GUYSMILEY-slow.log
and a fragment inside that log file might show something like this:
Ini and cnf changes require a MySQL daemon restart. In that configuration file a section similar to (my 5.6)
[mysqld]
basedir=C:\\Program Files\\MySQL\\MySQL Server 5.6\\
datadir=C:\\ProgramData\\MySQL\\MySQL Server 5.6\\Data\\
port=3306
log_warnings = 2
and (my 5.7)
[mysqld]
basedir=C:\\Program Files\\MySQL\\MySQL Server 5.7\\
datadir=C:\\ProgramData\\MySQL\\MySQL Server 5.7\\Data\\
port=3307
log_error_verbosity=2
the above is used within the [mysqld] section to play with settings. What I suggest is playing with this section with an innocuous setting like log_error_verbosity (5.7.2 and up) or similar, save it. Restart the deamon and determine if the variable (as Rick James would call settings because most really aren't dynamically settable). So a sanity check of select ##log_error_verbosity (5.7.2 and up) can confirm it the change is picked up. If it is, bingo, you are doing it right.
The Manual Page Server System Variables depicts the variables (settings) and whether or not they can be dynamically set/changed after the config file load via commands. Dynamic changes are reverted upon daemon restart.
How one would dynamically change a variable might look like:
SET GLOBAL log_error_verbosity=2;
Again, only certain variables are available in certain MySQL versions, such as the above, not available in older versions.
Also note multiple versions of MySQL running concurrently on a server. On mine i have 5.6.31 and 5.7.14. To access a different one via command line tools, use something like the -P 3307 switch to point at the one running on port 3307. Note the uppercase P as opposed to lowercase (which would mean prompt for password).
Determine if multiple instances are running. I use port checks such as
sudo netstat -tulpn (Linux)
netstat -aon | more (Windows, the top part, State=LISTENING)
Unfortunately these types of changes and trial and error take time and are very frustrating. Sorry I do not have a quick and easy answer for all cases.
Addendum
Notes here related to comments. In the below, w-x-y-z is a redacted IP Address.
On a Linux box (amazon ec2 redhat btw):
select ##slow_query_log;
-- 0 (so it is turned off)
SELECT ##slow_query_log_file;
-- /var/lib/mysql/ip-w-x-y-z-slow.log
select ##version;
-- 5.7.14
set global slow_query_log=1;
Error Code: 1227. Access denied; you need (at least one of) the SUPER privilege(s) for this operation 0.094 sec
(ok I was in MySQL Workbench as a dummied down user, off to do it as root via MySQL cmd line ...
mysql> set global slow_query_log=1;
Query OK, 0 rows affected (0.01 sec)
mysql> select ##slow_query_log;
+------------------+
| ##slow_query_log |
+------------------+
| 1 |
+------------------+
1 row in set (0.00 sec)
btw Workbench user can confirm the above `1`
at shell as linux user:
[ec2-user#ip-w-x-y-z ~]$ cd /var/lib/mysql
[ec2-user#ip-w-x-y-z mysql]$ sudo ls -la
(there were many files, only one needed to show you below)
-rw-r-----. 1 mysql mysql 179 Sep 19 01:47 ip-w-x-y-z-slow.log
[ec2-user#ip-w-x-y-z mysql]$ sudo vi ip-w-x-y-z-slow.log
(Header stub, the entire contents, no slow queries yet, log seen below):
/usr/sbin/mysqld, Version: 5.7.14 (MySQL Community Server (GPL)). started with:
Tcp port: 3306 Unix socket: /var/lib/mysql/mysql.sock
Time Id Command Argument
SHOW VARIABLES LIKE 'log_output'; to verify that it is set to FILE or FILE,TABLE.
Recently I have installed Percona 5.7.12 in my linux box but I have not found any configuration file(like my.cnf for mysql) where i can set/modify global variables.
I want to change the values of default system variables like 'sql_mode', password_policy etc.I tried setting values like *SET GLOBAL sql_mode = 'ALLOW_INVALID_DATES';* but after restart of mysqld instance, it seems old default values are retained.How can I set those values permanently so that modified values are retained??? Any help would be appreciated.
According to Percona's install guide, the config file should be located under /etc/my.cnf:
Percona Server stores the data files in /var/lib/mysql/ by default. You can find the configuration file that is used to manage Percona Server in /etc/my.cnf.
If there is no such file in the /etc directory, then you can create it yourself and set any config parameters there. Parameters in the config file are preserved across MySQL system restarts.
It's this file /etc/mysql/conf.d/mysql.cnf in my Percona 5.7 installation.
I can find it by following these steps:
mysqladmin --help
The output contains these lines:
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
The first file (/etc/my.cnf) doesn't exist on my machine.
The second one (/etc/mysql/my.cnf) contains these lines:
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/percona-server.conf.d/
This file /etc/mysql/conf.d/mysql.cnf in the first directory contains the settings I would expect in /etc/my.cnf.
I was facing this same issue. Found that the xtrabackup versions at both the servers were way different (8.0.23 at the source where the backup was taken and 2.4.9 at the destination where I was trying to restore the backup).
As soon as I upgraded the xtrabackup version to 8.0.23 on the destination server, the "prepare" went smoothly without any issues.
I am trying to use the CONVERT_TZ in MySQL. From what i have looked up the time_zone tables in the mysql schema need to be populated. I have looked this up on many different site and followed a few tutorials including this tutorial but the tables are still not populated
The 15 timezone files have been added to my C:\Program Files\MySQL\MySQL Server 5.6\data\mysql directory.I have tried both to add these files manually and use the mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql as seen here. I have restarted the MySQL service but the tables have still not been updated both ways
Does any have any ideas why?
Solution :
I found the answer to this here. It seemed that even do I had a folder structure of C:\Program Files\MySQL\MySQL Server 5.6 when i ran the command show variables like 'datadir in MySQL it was pointing to C:\ProgramData\MySQL\MySQL Server 5.6 which is a hidden folder so i did not see it before
When i added the timezone files to C:\ProgramData\MySQL\MySQL Server 5.6\data\mysql it worked
I want to change the default port number of MySQL server presently it is 3306. I want to change it to 3360.
I have tried:
-- port=3360
But things are not working for me. Please provide query to change port not any configuration. I am using Windows 8 64 bit.
You need to edit your my.cnf file and make sure you have the port set as in the following line:
port = 3360
Then restart your MySQL service and you should be good to go. There is no query you can run to make this change because the port is not a dynamic variable (q.v. here for MySQL documentation showing a table of all system variables).
If you're on Windows, you may find the config file my.ini it in this directory
C:\ProgramData\MySQL\MySQL Server 5.7\
You open this file in a text editor and look for this section:
# The TCP/IP Port the MySQL Server will listen on
port=3306
Then you change the number of the port, save the file.
Find the service MYSQL57 under Task Manager > Services and restart it.
On newer (for example 8.0.0) the simplest solution is (good choice for a scripted start-up for example):
mysqld --port=23306
When server first starts the my.ini may not be created where everyone has stated. I was able to find mine in C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.6
This location has the defaults for every setting.
# CLIENT SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by MySQL client applications.
# Note that only client applications shipped by MySQL are guaranteed
# to read this section. If you want your own MySQL client program to
# honor these values, you need to specify it as an option during the
# MySQL client library initialization.
#
[client]
# pipe
# socket=0.0
port=4306 !!!!!!!!!!!!!!!!!!!Change this!!!!!!!!!!!!!!!!!
[mysql]
no-beep
default-character-set=utf8
Go to installed mysql path and find bin folder,open my.ini and search 3306 after that change 3306 to 3360
Actually, you can just run the service using /mysqld --PORT 1234, it would force mysql to run on the specified port without change the cnf/ini file.
I just cought a case that cnf didn't work. It was weired... so I just use the cmd line as the shortcut and it works!
try changing the connection port to 8012
open xampp as administrator
Mysql config => my.ini change the port from 3306 to 8012
close and run it again
I hope it will work.
If you are using windows and installed the database as a service, which is the default, you should find your configuration file by opening your services management console.
For instance: win + r and then type services.msc
Look for a service called MySQL or MariaDB.
On the general tab of the properties of this service you can find a path to your mysqld.exe file and the arguments to start the exe. The --defaults-file argument should point to your configuration file.
Edit your configuration file and restart the MySQL service.
In Windows 8.1 x64 bit os, Currently I am using MySQL version :
Server version: 5.7.11-log MySQL Community Server (GPL)
For changing your MySQL port number, Go to installation directory, my installation directory is :
C:\Program Files\MySQL\MySQL Server 5.7
open the my-default.ini Configuration Setting file in any text editor.
search the line in the configuration file.
# port = .....
replace it with :
port=<my_new_port_number>
like my self changed to :
port=15800
To apply the changes don't forget to immediate either restart the MySQL Server or your OS.
Hope this would help many one.
Change my.cnf file and add this line or change it port=3360
at my fedora 34
sudo vi /etc/my.cnf
add This line ==> port=3360
The best way to do this is take backup of required database and reconfigure the server.
Creating A Backup
The mysqldump command is used to create textfile “dumps” of databases managed by MySQL. These dumps are just files with all the SQL commands needed to recreate the database from scratch. The process is quick and easy.
If you want to back up a single database, you merely create the dump and send the output into a file, like so:
mysqldump database_name > database_name.sql
Multiple databases can be backed up at the same time:
mysqldump --databases database_one database_two > two_databases.sql
In the code above, database_one is the name of the first database to be backed up, and database_two is the name of the second.
It is also simple to back up all of the databases on a server:
mysqldump --all-databases > all_databases.sql
After taking the backup, remove mysql and reinstall it. After reinstalling with the desired port number.
Restoring a Backup
Since the dump files are just SQL commands, you can restore the database backup by telling mysql to run the commands in it and put the data into the proper database.
mysql database_name < database_name.sql
In the code above, database_name is the name of the database you want to restore, and database_name.sql is the name of the backup file to be restored..
If you are trying to restore a single database from dump of all the databases, you have to let mysql know like this:
mysql --one-database database_name < all_databases.sql