Is there a way, how can I print default configuration variables or configuration sections for mysql/mariadb client?
I have a configuration file for example:
[client]
user = abc
passw = bcd
!include /another/my.cnf
!includedir /another/configurations/
In /another/my.cnf I have
[clientA]
user = abc
passw = bcd
host = example.com
I would like to know wheter the configuration section [clientA] exists.
Now when I connect to mysql --defaults-group-suffix=B it still connects me based on the [client] section without any warning, that suffix B is nonexistent.
Is there any command that should print me the combined my.cnf file with it's sections?
You can use my_print_defaults utility. Use of --defaults-group-suffix makes the utility read options from groups with the specified suffix alongwith the usual groups.
Related
On server 1 (lets call it 1.1.1.1 , I have Wordpress installed, which has its own MySQL database.
On server 2 (lets call it 2.2.2.2) , I have only MySQL on Ubuntu, with PhpMyAdmin installed.
I am attempting to connect FROM Wordpress (functions.php) FROM server 1, to server 2's MySQL database through the following:
$mydb = new wpdb('rruser','password','dbname', '2.2.2.2');
Following this connection, everything else is fine.
Upon loading the shortcode through a page, the page does not load the content in the shortcode. I am assuming the connection has timed out.
Please can someone advise how I can go about connecting to an external database?
I have created a new user on "2.2.2.2" and granted priveleges to "dbname".
CREATE USER 'rruser'#'1.1.1.1' IDENTIFIED WITH mysql_native_password AS '***';`
`GRANT USAGE ON *.* TO 'rruser'#'1.1.1.1' REQUIRE NONE WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;`
`GRANT ALL PRIVILEGES ON `rail`.* TO 'rruser'#'1.1.1.1';
My MySQL my.cnf file looks like the following on the remote server which I would like to connect to (2.2.2.2)
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
[mysqld]
innodb_file_per_table = 1
Many thanks in advance.
I have resolved my problem by adding bind-address to 2.2.2.2's my.cnf file, as well as allowing mysql's ports in UWF, including TCP and 8080.
Upon rebooting my server the problem is resolved
I'm using MySQL / 10.1.29-MariaDB-6 on Kali Linux 2018 VM.
I have the following entry in mariadb.cnf, mysql.cnf, and 50-server.cnf.
general_log_file = /var/log/mysql/mysql.log
general_log = 1
The conf file shows that the following config files are used to determine options:
The MariaDB/MySQL tools read configuration files in the following order:
/etc/mysql/mariadb.cnf (this file) to set global defaults,
/etc/mysql/conf.d/*.cnf to set global options.
/etc/mysql/mariadb.conf.d/*.cnf to set MariaDB-only options.
~/.my.cnf to set user-specific options.
Logging IS working to the file specified, but whenever I try to type the following mysql command, I am met with the following error:
root#kali:/var/log/mysql# mysql -u root -p
mysql: unknown variable 'general_log_file=/var/log/mysql/mysql.log'
How to fix this error?
Check the sections of the config file(s) where general_log_file option is set. It must be [mysqld], or [server], or [mariadb] and alike, but it must not be [mysql] or [client] or alike. general_log_file is a server-only option.
I'm using MySQL server version: 10.1.23-MariaDB-9+deb9u1 Raspbian 9.0 on a Raspberry Pi.
This is my /etc/mysql/my.cnf:
# The MariaDB configuration file
#
# The MariaDB/MySQL tools read configuration files in the following order:
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.
#
# If the same option is defined multiple times, the last one will apply.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
# Import all .cnf files from configuration directory
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/
#bind-address = 0.0.0.0
I've tried this:
sudo mysql_secure_installation
Change root password: y
Password
Retyped password
Remove anonymous users: y
Disallow root login remotely: n
Remove test database: y
Reload priviledges: y
CREATE USER 'root'#'%.%.%.%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'root'#'%.%.%.%' WITH GRANT OPTION;
FLUSH PRIVILEDGES;
service mysql restart
In my.cnf, with bind-address commented, I can access from localhost, but not from remote host using SQL Workbench.
With bind-address uncommented, I cannot access from localhost, but I can access from remote host using SQL Workbench, e.g.:
mysql -u root
mysql: unknown variable 'bind-address=0.0.0.0'
This is my users table:
MariaDB [(none)]> select user, host, password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| root | localhost | *054D119DEAD56E226D8356557796BFA72E71BA40 |
| root | %.%.%.% | *054D119DEAD56E226D8356557796BFA72E71BA40 |
| root | % | *054D119DEAD56E226D8356557796BFA72E71BA40 |
+------+-----------+-------------------------------------------+
How do I configure the server to allow local and remote access for root from any IP?
Add a line over bind-address = 0.0.0.0 with [mysqld] like:
[mysqld]
bind-address = 0.0.0.0
In your case both, the server and the local client, reads the bind address and the client want to connect to the IP 0.0.0.0
According to this link it seems that the mysql client doesn’t recognize the bind address.
In order to connect locally I have to use this line:
mysql --no-defaults -u[username] -p[password] [database]
Just in case - I first put the bind-address between the lines and it did not work after
systemctl restart mysqld
With bind-address at the end it worked:
# The MariaDB configuration file
#
# The MariaDB/MySQL tools read configuration files in the following order:
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.
#
# If the same option is defined multiple times, the last one will apply.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
# Import all .cnf files from configuration directory
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/
[mysqld]
bind-address = 0.0.0.0
I have a mysql.sock file located at:
/tmp/mysql.sock
But the my.cnf is pointing to this location:
socket=/var/lib/mysql/mysql.sock
Is this correct?
The socket declaration should be located under [mysqld] in your my.cnf. If you have declared it there and still pointing to another place such as tmp, then your my.cnf file that you have been editing is not being read when mysql starts or there is another my.cnf overriding the one you have been editing. The case may also be that there is a second Socket declaration in the same my.cnf file that is overriding the one you expect to be read at start by mysql.
You can check its absolute path by logging into mysql and running:
mysql> show variables like 'socket';
+-----------------------------------------+-------------------------------+
| Variable_name | Value |
+-----------------------------------------+-------------------------------+
| socket | /yourpath/mysql.sock |
+-----------------------------------------+-------------------------------+
1 rows in set (0.00 sec)
There is no right or wrong place on linux for saving sockets, except on external devices which are unmounted at any time or folders which are emptied from time to time. You need to configure where you want to place it.
For the MySQL console client there is something more to consider: The client seems to use the socket configuration value provided in [client] instead of [mysqld]. If you have a multiple MySQL server setup like i have (4.1, 5.5, 5.7), you probably want to use a "--defaults-extra-file" option with the socket written in the [client] part for each different server. The socket needs to be the same as the one defined in the my.cnf [mysqld] part used on the server.
Here is an example defaults-extra-file.cnf, remember to change the user, password and socket to your needs - and keep it on access rights 400 (there is a password stored after all):
[client]
user = guardian
password = I-4m.Gr00t!
host = localhost
socket = /var/run/mysqld/mysqld-5.6.sock
This only applies though if you are using "localhost" as the value for "host". If you have multiple local addresses (127.0.0.2, 127.0.0.3), you need to leave the config variable for "host" on "localhost" to use the configured socket. Otherwise the client will connect to the server using TCP.
This was tested on my Debian 9.5 Server with MySQL 4.1.22, 5.5.49 and 5.7.19 and their respective clients.
I am attempting to move a mysql db onto an upgraded server with a newer version of ubuntu running (15.04), and after installing LAMP, I went to edit the bind address in the my.cnf file. The below is all I see in /etc/mysql/my.cnf. I added [mysqld] and the bind address = new address but nothing seems to allow my remote client to connect to this db. It is online and the ip address should be correct. What am i missing? Why is this my.cnf so bare?
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
stupid me, apparently in this version it is the mysqld.cnf under /etc/mysql/mysql.conf.d/. Oh well. Posting this in case anyone else has problems.....
In ubuntu 15.04 the MySQL Server configure file is in:
/etc/mysql/mysql.conf.d/mysqld.cnf
You can find bind-address here.Comment it, and restart your MySQL Server use :
service mysql restart
Then you can access your MysqlServer from other computer. If you don't, perhaps you need grant some right to the user you use.
You can see MySQL Server bind-address use:
netstat -tap | grep mysql
So you know whether the configure take effect.
Depending on your linux distro your my.cnf (as well as the rest of your data directory) may be in /var/lib/mysql folder.
You could also run the find command to look for the file: find -name 'my.cnf'.
I suggest running this command as root, in your root directory.
Once you have located the correct my.cnf file there will be a parameter under [mysqld] section that looks like this:
bind-address = 127.0.0.1
Comment this parameter out with a # and save the edited my.cnf file. Restart the Mysql server and you should be able to connect remotely from any IP as long as the user you are trying to connect with as the correct permissions and host(%).
You can check this by running:
select user, host from mysql,user;
and show grants for 'youruser'#'yourhost';
grants and privileges for Mysql.