Reinstall MySQL (mariadb) in Debian Stretch - mysql

I removed mysql completely including configuration files and when I try to reinstall, there is no mysql.socket (I searched in /var/lib/mysql/ and there's nothing.

Typically you will see mysql.sock file when you start the mysql daemon process. This is create the sock file.
But you can also search and see whether it has created somewhere.
netstat -ln | grep -o -m 1 -E '\S*mysqld?\.sock'
or
you can check with this command:
% mysqladmin variables
If you want to create the file, you can do this
mkdir /var/mysql
ln -s /tmp/mysql.sock /var/mysql/mysql.sock
This thread explains things in more details.

Related

Can I change the global port number without my.cnf file?

I made the following mysql container in the docker.
docker run -p 3307:3307 --name todolist -e MYSQL_ROOT_PASSWORD=1234 -e MYSQL_DATABASE=todolist -e MYSQL_USER=allssu -e MYSQL_PASSWORD=1234 -d mysql
However, I confirmed that the port of mysql on the docker is still 3306. So I tried to modify the port number in the my.cnf file in the /etc/mysql path. But, only the conf.d file exists in the /etc/mysql folder, and there is no my.cnf file.
To make matters worse, an error occurs in my bash that the apt-get command does not work.
bash-4.4# apt-get update
bash: apt-get: command not found
bash-4.4# apt-get install vim
bash: apt-get: command not found
First, I want to find the invisible my.cnf file in the etc/mysql folder. Also I want to set the port of this container(name:todolist) to 3307, is there any way?
And, I want to use the vi command in bash.
I would appreciate it if you could consider this matter together.
I tried the following and still couldn't find my.cnf.
bash-4.4# mysqld --verbose --help | grep -A 1 'Default options'
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf
result:
bash-4.4# pwd
/etc/mysql
bash-4.4# ls
conf.d

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 do I run mysqld as root in the official MySql docker image?

First off, I know not to run as root normally. I have an abnormal situation: I need to use mysqldump with the --tab argument, which requires permission to write to disk, and I want to use those files outside the Docker container. I could explain why running mysqld as root makes this easier, but isn't this question long enough? Running as root is safe in this case because the container will be used only for running tests and for updating DB backup scripts based on SQL migration scripts, and it will be started to do 1 job and then taken back down again.
When I google for how to run mysqld as root, I find the answer indirectly given in instructions on how to NOT run as root. Among other things in order to run mysqld as user_name:
Start the server as user user_name. Another alternative is to start mysqld as the Unix root user and use the --user=user_name option.
To start the server as the given user automatically at system startup time, specify the user name by adding a user option to the [mysqld] group of the /etc/my.cnf option file or the my.cnf option file in the server's data directory.
Do we do one of those? Both of those? I'll assume both just in case. But do they really mean /etc/my.cnf, or does that depend on the installation (e.g. what Linux distribution)? E.g. Docker image mysql:5.6 has /etc/mysql/my.cnf. The directions for the MySql Docker image advise mounting a volume at /etc/mysql/conf.d which is referenced in the aforementioned my.cnf. (Doing so overwrites 2 configuration files that are there by default, so I used a COPY command in my Dockerfile instead to merely add a config file.) The file does make it into the container:
root#4f612d10a690:/etc/mysql/conf.d# cat my.cnf
[mysqld]
user=root
One further requirement from the MySql manual is to add the --user=root argument to mysqld. The official MySql image calls mysqld via its CMD, so I override that in my Dockerfile. My CMD command does indeed run (it is run in 2 places in official MySql image's entrypoint script):
# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
mysql 1 0.1 2.8 1452788 472756 ? Ssl 14:24 0:01 mysqld --user=root
Note that mysqld has the --user=root command I provided, but is running as the mysql user, not as root.
Here's my full Dockerfile:
FROM mysql:5.6
VOLUME ["/var/lib/mysql-files"]
COPY ["my.cnf", "/etc/mysql/conf.d"]
CMD ["mysqld", "--user=root"]
My only guess as to why it's not running as root is that they mysql image's entrypoint script changes to the mysql user before running:
# allow the container to be started with `--user`
if [ ...blah... -a "$(id -u)" = '0' ]; then
...blah...
exec gosu mysql "$BASH_SOURCE" "$#"
fi
The above snippet basically says, if the user is root, then run the supplied arguments (the CMD + args in this case) as the mysql user.
Is running mysqld as root simply not supported by the official MySql Docker image?
Note: this is how to run mysqld process as SO's root user, and not how to get the root MySQL user.
I don't know whether exists a better approach but this works.
Viewing the official entrypoint.sh, it seems that it has no support of chaging the default mysql user
I realized how to run mysql as root but you need to have already initialized the data directory.
Step 1) Start a normal mysql in order to initialize a volume (the mysql entrypoint.sh will do that job):
docker run \
--rm \
-v $(pwd)/mysql/:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD="abc" \
mysql:5.6
Step 2) Stop and remove that container:
docker stop <container-id>
Step 3) Start again a new mysql process based on the data dir that has been created, but this time avoid to run the official mysql entrypoint:
docker run \
-v $(pwd)/mysql/:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD="abc" \
--entrypoint mysqld \
mysql:5.6 \
--user root
Step 4) Check it:
▶ docker exec -it 4add4d065c3e bash
root#4add4d065c3e:/# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 2.8 23.0 1314864 471104 ? Ssl 15:12 0:00 mysqld --user root
root 28 3.0 0.1 20248 3040 ? Ss 15:12 0:00 bash
root 34 0.0 0.1 17500 2068 ? R+ 15:12 0:00 ps aux

Mysql error 1036 Table is read only

I'm using xampp to run mysql, and I've created a database for a lost and found website.
The database is really simple, only two tables are used:
students
&
lost_items
I am trying to insert data into the students table, but it keeps saying that this table is read only. I've read some solutions and they said I need to use sudo and set the group privileges, but where do I put in these commands?
I had same problem in ubuntu and xampp.
In file config, after block innodb set --> innodb_force_recovery = 1
sudo chmod 777 -R /opt/lampp/var/mysql
Сomment out line #innodb_force_recovery = 1
restart MySQL
Get your data directories by following commands.
sudo cat /etc/mysql/my.cnf | grep -i datadir
or
sudo cat /etc/my.cnf | grep -i datadir
sudo chown -cR mysql:mysql /Path/mysql/datadir/
And restart mysql process
/etc/init.d/mysql stop
/etc/init.d/mysql start
Hope this helps.

MySQL Start Error

I am trying to install MySQL 5.6.17 on Ubuntu Linux and I am having difficulties doing so. I opened the MySQL Reference and opened "Installing MySQL on Unix/Linux Using Generic Binaries". I followed the following step:
shell> groupadd mysql
shell> useradd -r -g mysql mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &
//Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server
After that when I try to start MySQL using /etc/init.d/mysql.server start I get the following error:
Couldn't find MySQL server (/usr/bin/mysqld_safe)
I looked in /usr/bin and I found mysqld_safe. Any suggestions on how to fix that problem. Please reply with a detailed solution.
Thank You
It seems you have installed Mysql in "/usr/local" and init script is looking for binaries in "/usr"
Change the "basedir" in /etc/init.d/mysql.server to :
basedir=/usr/local
The fact that you found /usr/bin/mysqld_safe suggests that MySQL in some shape or form was preinstalled on your OS. This can cause some confusion, in particular due to location of config files.
So for instance, on some versions of Ubuntu, the packages mysql-common is pre-installed, which means you might have an /etc/mysql/my.conf file with some defaults in it. When you install from the tar file to /usr/local, follow the INSTALL-BINARIES (or equivalent) instructions, and try to start /etc/init.d/mysql.server start you might get errors as the one you report ("Couldn't find MySQL server (/usr/bin/mysqld_safe)"), because the default configuration in /etc/init.d/mysql.server and any /etc/my.cnf that you created (optional step during install) is getting over-ridden by a setting in the OS installed /etc/mysql/my.conf. Note that this might happen even if you change the values in /etc/init.d/mysql.server and/or /etc/my.cnf.
One way out is to merge /etc/my.cnf and /etc/mysql/my.cnf into a single file at one of these locations, with the correct defaults that you wish to use.