centos 7 Mysql 5.6.3 change data directory error - mysql

I try to change Mysql 5.6 data directory in centos 7 from default dir /var/lib/mysql to target dir /data1/mysqldata/mysql.
Follow is my operation step by step
1.Stop mysql service
2.Create target directory and chown
mkdir /data1/mysqldata
chown -R mysql:mysql /data1/mysqldata
2.Change /etc/my.cfg to below code
[mysqld]
datadir=/data1/mysqldata/mysql
socket=/data1/mysqldata/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[client]
port=3306
socket=/data1/mysqldata/mysql/mysql.sock
4.Move data from default directory to target
mv /var/lib/mysql /data1/mysqldata/
5.Start mysql service
But I get error from /var/log/mysqld.log like this
190813 10:40:23 mysqld_safe Logging to '/var/log/mysqld.log'.
190813 10:40:23 mysqld_safe Directory '/data1/mysqldata/mysql' for UNIX socket file don't exists.
It's strange that Mysql run normaly in the default directory /var/lib/mysql when I undo all my config
My machine version is CentOS Linux release 7.6.1810 (Core), and Mysql Version is mysql Ver 14.14 Distrib 5.6.45, for Linux (x86_64)

Related

lower_case_table_names Settings in MySQL 8.0.12

I've just compiled the version MySQL 8.0.12 in a Ubuntu 16.0.4.
After following the instructions in the website and making the following my.cnf file:
[mysqld]
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
port=3306
log-error=/usr/local/mysql/data/localhost.localdomain.err
user=mysql
secure_file_priv=/usr/local/mysql/mysql-files
local_infile=OFF
log_error = /var/log/mysql/error.log
# Remove case sensitive in table names
lower_case_table_names=1
I get the following error:
2018-08-11T19:45:06.461585Z 1 [ERROR] [MY-011087] [Server] Different lower_case_table_names settings for server ('1') and data dictionary ('0').
What should I change so that data dictionary is aligned to server settings?
So far, I can get it to work with a workaround (I originally posted on askubuntu): by re-initializing MySQL with the new value for lower_case_table_names after its installation. The following steps apply to a new installation. If you have already data in a database, export it first to import it back later:
Install MySQL:
sudo apt-get update
sudo apt-get install mysql-server -y
Stop the MySQL service:
sudo service mysql stop
Delete the MySQL data directory:
sudo rm -rf /var/lib/mysql
Recreate the MySQL data directory (yes, it is not sufficient to just delete its content):
sudo mkdir /var/lib/mysql
sudo chown mysql:mysql /var/lib/mysql
sudo chmod 700 /var/lib/mysql
Add lower_case_table_names = 1 to the [mysqld] section in /etc/mysql/mysql.conf.d/mysqld.cnf.
Re-initialize MySQL with --lower_case_table_names=1:
sudo mysqld --defaults-file=/etc/mysql/my.cnf --initialize --lower_case_table_names=1 --user=mysql --console
Start the MySQL service:
sudo service mysql start
Retrieve the new generated password for MySQL user root:
sudo grep 'temporary password' /var/log/mysql/error.log
Change the password of MySQL user root either by:
sudo mysql -u root -p
and executing:
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPa$$w0rd';
afterwards, OR by calling the "hardening" script anyway:
sudo mysql_secure_installation
After that, you can verify the lower_case_table_names setting by entering the MySQL shell:
sudo mysql -u root -p
and executing:
SHOW VARIABLES LIKE 'lower_case_%';
Expected output:
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| lower_case_file_system | OFF |
| lower_case_table_names | 1 |
+------------------------+-------+
As per this link, lower_case_table_names should be set together with --initialize option.
MySQL Documentation says
lower_case_table_names can only be configured while initializing the server. Changing the lower_case_table_names setting after the server is initialized is prohibited.
https://dev.mysql.com/doc/refman/8.0/en/identifier-case-sensitivity.html
The best way to prevent this problem is :At first add
[mysqld]
lower_case_table_names=1
then start mysql service for first time.
But anyway if you have started the server already,to solve your problem:
1.stop mysql:
systemctl stop mysql
2.clean data directory or change the default, the following is for new installations , if you have data in your database BACK UP them beforehand
rm -rf /var/lib/mysql
3.Insert lower_case_table_names = 1 in your my.cnf:
[mysqld]
lower_case_table_names=1
4.Start again
systemctl start mysqld
To fix this issue,
Just take the backup of the existing db Schema using the following command inside bin folder (/usr/local/mysql/bin)
./mysqldump -uroot -p password > dump.sql
Once the backup is taken delete the existing data folder in Mysql Home(/usr/local/mysql/) using the command
rm -rf data
Now add the configuration as "lower_case_table_names=1" in my.cnf under MYSQLD section (/etc/my.cnf)
Now Initialize the data directory using the following command inside bin directory (/usr/local/mysql/bin)
For Secure mode
./mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --console
For Insecure mode
./mysqld --defaults-file=/etc/my.cnf --initialize-insecure --user=mysql --console
Once the data directory initialized, For Insecure mode repeat the Installation again and For Secure mode use the root password which is initialized during the run time of data directory Initialization.
Now import the existing dump file inside the Mysql Server using the command inside (/usr/local/mysql/bin) directory
./mysql -uroot -p password < file.sql
If anyone runs into this issue now, if you already initialized mysql, meaning you already had it up and running and then this error occurred, just comment out this line in the my.ini file.
lower_case_table_names=

how to enable mysql bin log

OS: Mac OS X Hi Sierra(10.13.1)
MySQL: 5.7.20 (install by homebrew)
I want to enable bin log, so I should edit my.cnf file,
I typed below command to find my.cnf file
mysql --verbose --help | grep my.cnf
and result
/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf
/etc/my.cnf, /etc/mysql/my.cnf isn't exist in my mac.
So, I edit /usr/local/etc/my.cnf file.
[mysqld]
bind-address = 127.0.0.1
log-bin = ~/log
and I start mysql but it can't start.
mysql.server start
Starting MySQL
... ERROR! The server quit without updating PID file (/usr/local/var/mysql/*.pid).
When I remove bin-log in my.cnf, it can start!
How can I enable bin log??
Standby counsel
I missed server-id property in my.cnf...

Mysql server won't work when using another data directory

I have an amazon ec2 instance running on Amazon Linux AMI. I'm trying to move the data directory for mysql on a second volume (mounted on /home/ec2-user/data) with following config file (/etc/my.cnf) but mysql fails to start:
[mysqld]
datadir=/home/ec2-user/data/mysql
socket=/home/ec2-user/data/mysql/mysql.sock
log-bin=/var/log/mysql/mariadb-bin
log-bin-index=/var/log/mysql/mariadb-bin.index
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[client]
port=3306
socket=/home/ec2-user/data/mysql/mysql.sock
I get these error messages in the log file:
2017-10-12 14:06:33 20082 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
2017-10-12 14:06:33 20082 [ERROR] Can't start server : Bind on unix socket: Permission denied
2017-10-12 14:06:33 20082 [ERROR] Do you already have another mysqld server running on socket: /home/ec2-user/data/mysql/mysql.sock ?
2017-10-12 14:06:33 20082 [ERROR] Aborting
When I set the config file back to former settings (to the backup of the data folder) everything works fine:
[mysqld]
datadir=/var/lib/mysql.bak
socket=/var/lib/mysql.bak/mysql.sock
log-bin=/var/log/mysql/mariadb-bin
log-bin-index=/var/log/mysql/mariadb-bin.index
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[client]
port=3306
socket=/var/lib/mysql.bak/mysql.sock
What could be the cause of this problem? I've already checked for the permissions on the new data folder but that doesn't change anything.
Run this command:
chgrp -R mysql /home/ec2-user/data/mysql
chown -R mysql /home/ec2-user/data/mysql
Can you try the following config file ?
[mysqld]
datadir=/home/ec2-user/data/mysql
socket=/var/lib/mysql.bak/mysql.sock
log-bin=/var/log/mysql/mariadb-bin
log-bin-index=/var/log/mysql/mariadb-bin.index
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[client]
port=3306
socket=/var/lib/mysql.bak/mysql.sock

How can I create a mariadb drop in replacement for MAMP [duplicate]

I successfully installed mariadb, but MAMP continues to use the copy of mysql located in its bin folder; specifically:
/Applications/MAMP/Library/bin/mysql
How do I get MAMP to use mariadb, which in my case is located in /usr/local/bin/mysql?
I tried creating a symbolic link in MAMP's bin folder to point to /usr/local/bin, but that didn't work. Hmm.
MAMP uses MAMP/bin/startMysql.sh to start mysql. Try to change it.
here's how i do it so that you can use either mysql or mariadb since mariadb is a drop in replacement (typing this from memory, so please let me know if there are some mistakes)...
0) make a backup of your mysql db dir just in case, and do some mysql prep just in case
$ cp -R /Applications/MAMP/db/mysql /Applications/MAMP/db/mysql.2013-02-06-1850.bak
$ /Applications/MAMP/bin/repairMysql.sh
$ /Applications/MAMP/bin/quickCheckMysqlUpgrade.sh
$ /Applications/MAMP/bin/upgradeMysql.sh
1) make a copy or take note of some settings in your my.cnf file. It can be located in a variety of different places, so to find them all (there are a bunch):
$ locate my.cnf
/Applications/MAMP/conf/my.cnf
/etc/my.cnf
/usr/local/etc/my.cnf
/usr/local/etc/my.cnf.d
/usr/local/etc/my.cnf.d/client.cnf
/usr/local/etc/my.cnf.d/mysql-clients.cnf
/usr/local/etc/my.cnf.d/server.cnf
2) figure out which my.cnf was loaded (for MAMP, it MAY be in /Applications/MAMP/conf/my.cnf)
$ /usr/local/bin/mysql --help | grep my.cnf
order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf
$ /Applications/MAMP/Library/bin/mysql --help | grep my.cnf
order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf /Applications/MAMP/conf/my.cnf ~/.my.cnf
3) make a backup of the my.cnf in /etc/my.cnf and edit my.cnf to make sure it's got a few parameters in there, most importantly the port, socket, and datadir settings so that mariadb will know where to look for your db files:
$ sudo cp /etc/my.conf /etc/my.cnf.2013-02-06-1858.bak
$ sudo vi /etc/my.cnf
port = 3306
socket = /Applications/MAMP/tmp/mysql/mysql.sock
datadir = /Applications/MAMP/db/mysql
tmpdir = /Applications/MAMP/tmp/mysql
4) add any mariadb specific config options you may want in a [mariadb] section
5) install mariadb (i like using brew, but pick your poison)... and you can really do this any time
$ brew install mariadb
6) make a symbolic link from the my.conf from step two
$ sudo ln -s /Applications/MAMP/conf/my.cnf /etc/my.cnf
6a) you can put your my.cnf anywhere, as long as there's a copy or link to it in /etc/my.cnf... the goal here is to have mariadb and MAMP's implementation of mysql use the same config settings.
7) now make a shell shell script to load apache and mariadb
$ mkdir -p ~/scripts/mamp
$ touch ~/scripts/mamp/startSomething.sh ~/scripts/mamp/stopSomething.sh
$ chmod ug+rx ~/scripts/mamp/*Something.sh
8) get/take note of the current start/stop script for apache (it'll prob won't be anything fancy)
$ more /Applications/MAMP/bin/startApache.sh
$ more /Applications/MAMP/bin/stopApache.sh
9) get the installed mariadb path, and make sure it's the mariadb version
$ which mysql
/usr/local/bin/mysql
$ mysql --version
mysql Ver 15.1 Distrib 5.5.29-MariaDB, for osx10.8 (i386) using readline 5.1
10) now edit startSomething.sh
# /bin/sh
/Applications/MAMP/Library/bin/apachectl start
/usr/local/bin/mysql.server start &
11) do the same for stopSomething.sh
# /bin/sh
/Applications/MAMP/Library/bin/apachectl stop
/usr/local/bin/mysql.server stop &
12) that's it!. to start or stop things
$ ~/scripts/mamp/startSomething.sh
$ ~/scripts/mamp/stopSomething.sh
if you want the vanilla MAMP, use the MAMP app that came with MAMP. otherwise, have fun with this slightly faster database with a bunch of fun new features... but keep in mind that while mariadb is by design a drop in replacement for mysql, it's not true the other way around (MariaDB v MySQL compatibility)

How to change mysql.sock?

I have installed mysql through binary installation and followed below steps
http://dev.mysql.com/doc/refman/5.0/en/binary-installation.html
Right now sock files are craeted on /tmp/mysql.sock when mysql service is started.
I want to know which configuration files need to be edited to change the path of mysql.sock
I tried the following steps to change mysql.sock path from /tmp/mysql.sock to /var/lib/mysql/mysql.sock
1.I tried to enter socketpath in /etc/my.cnf
socket =/var/lib/mysql/mysql.sock
2./etc/init.d/mysql
basedir=/var/lib/mysql
datadir=/var/lib/mysql/data
socket=/var/lib/mysql/mysql.sock
Can anybody help me to fix this issue.
Setting these variables in my.cnf should work just fine (Tested locally, Ubuntu 10.10).
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
Just make sure you're restarting MySQL Service?
Below is what I did, this is on Fedora (Since you're using RHEL this should more mimic your setup):
[root#rudi /]# ls /var/lib/mysql/
ibdata1 ib_logfile0 ib_logfile1 mysql mysql.sock
[root#rudi /]# ls /var/run/mysqld/
mysqld.pid
[root#rudi /]# nano /etc/my.cnf
[root#rudi /]# service mysqld restart
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]
[root#rudi /]# ls /var/lib/mysql/
ibdata1 ib_logfile0 ib_logfile1 mysql
[root#rudi /]# ls /var/run/mysqld/
mysqld.pid mysql.sock
The only thing that I changed was socket= this time, and restarting still worked fine.
Are you sure that you're not editing socket within the [client] section of my.cnf? It must be under the [mysqld] section.