Terminal:
mysql -uroot -p
zsh: command not found: mysql
➜ ~ echo $PATH
/Users/zhangzhenxing/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:B:A:/sbin:/usr/local/git/bin
➜ ~ export PATH=$PATH:/usr/local/bin:/usr/local/mysql/bin
➜ ~ echo $PATH
/Users/zhangzhenxing/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:B:A:/sbin:/usr/local/git/bin:/usr/local/bin:/usr/local/mysql/bin
➜ ~ mysql -uroot -p
Enter password:
Execution of export PATH = $ PATH: / usr / local / bin: / usr / local / mysql / bin, after restarting the terminal, mysql still can not start, the reason I ask that God horse,
You need to re-execute the source order?
Try: echo "export PATH=\$PATH:/usr/local/bin:/usr/local/mysql/bin" >> ~/.zshrc, then restart your terminal.
If I understand your question correctly, you are trying to set the PATH environment variable when a new shell is started. This is typically done by editing your ~/.zshrc file.
Related
run mysql docker run -d --name=mysql-server -p 3306:3306 -e MYSQL_ROOT_PASSWORD=t123456 mysql:8.0.30
find command: find / -name mysqlbinlog,it only return one line:
sh-4.4# find / -name mysqlbinlog
find: '/proc/1/map_files': Permission denied
and run mysqlbinlog commmand failed:
sh-4.4# mysqlbinlog
sh: mysqlbinlog: command not found
--update--
i change version from 8.0.30 to 8.0.23 according to can't find mysqlbinlog in docker container [mysql/mysql-server:8.0.23] , and the command can be found , why is it missed in newer version?
Available in latest debian version
8.0.30-debian
Isn't possible to install MySQL in zsh in macOS?
I have been trying to install MySQL on my Mac.
zsh: command not found: mysql
Should I give up setting MySQL on zsh and try to do in bash?
% brew install mysql#5.7
==> Downloading https://ghcr.io/v2/homebrew/core/mysql/5.7/manifests/5.7.32-2
Already downloaded: /Users/stackover/Library/Caches/Homebrew/downloads/abe6a0a4787f4c4bd9c6d14e27d98d868c1f0f619cbbba601e8225--mysql#5.7-5.7.32-2.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/mysql/5.7/blobs/sha256:82867504
Already downloaded: /Users/stackover/Library/Caches/Homebrew/downloads/8db250bb2773af3411c71cf86232ed647cdf9366670c716c52574d--mysql#5.7--5.7.32.arm64_big_sur.bottle.2.tar.gz
==> Pouring mysql#5.7--5.7.32.arm64_big_sur.bottle.2.tar.gz
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
MySQL is configured to only allow connections from localhost by default
To connect run:
mysql -uroot
mysql#5.7 is keg-only, which means it was not symlinked into /opt/homebrew,
because this is an alternate version of another formula.
If you need to have mysql#5.7 first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/mysql#5.7/bin:$PATH"' >> ~/.zshrc
For compilers to find mysql#5.7 you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/mysql#5.7/lib"
export CPPFLAGS="-I/opt/homebrew/opt/mysql#5.7/include"
To have launchd start mysql#5.7 now and restart at login:
brew services start mysql#5.7
Or, if you don't want/need a background service you can just run:
/opt/homebrew/opt/mysql#5.7/bin/mysql.server start
==> Summary
🍺 /opt/homebrew/Cellar/mysql#5.7/5.7.32: 319 files, 233.7MB
stackover#stackoverjunoMacBook-Air ~ % echo 'export PATH="/opt/homebrew/opt/mysql#5.7/bin:$PATH"' >> ~/.zshrc
stackover#stackoverjunoMacBook-Air ~ % myql --version
zsh: command not found: myql
stackover#stackoverjunoMacBook-Air ~ % mysql --version
zsh: command not found: mysql
stackover#stackoverjunoMacBook-Air ~ % export LDFLAGS="-L/opt/homebrew/opt/mysql#5.7/lib"
stackover#stackoverjunoMacBook-Air ~ % export CPPFLAGS="-I/opt/homebrew/opt/mysql#5.7/include"
echo 'export PATH="/opt/homebrew/opt/mysql#5.7/bin:$PATH"' >> ~/.zshrc
export LDFLAGS="-L/opt/homebrew/opt/mysql#5.7/lib"
I checked if it installed:
stackover#stackoverjunoMacBook-Air ~ % mysql --version
but
zsh: command not found: mysql
I also tried this:
stackover#stackoverjunoMacBook-Air ~ % mysql -uroot
zsh: command not found: mysql
stackover#stackoverjunoMacBook-Air ~ % echo 'export PATH="/opt/homebrew/opt/mysql#5.7/bin:$PATH"' >> ~/.zshrc
stackover#stackoverjunoMacBook-Air ~ % mysql --version
zsh: command not found: mysql
Your shell does not automagically pick up new executables from your $path. For the shell to find the new executable, you will need to
rebuild your shell’s command lookup table with
hash -fr
restart your shell with
exec zsh
or open a new tab in your terminal.
Having issues running a shell script that invokes mysqdump to import the database. This is for the importing of a WordPress database from production to local dev machine. It worked in the past. But something must have changed on my local MacOs Mac Mini running OSX Sierra.
This is the script:
# sync-prod.sh
read -r -p "Do you solemnly swear that you have had fewer than 2 alcoholic beverages in the last hour and that you would really like to reset your development database and pull the latest from production? [y/N] " response
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]
then
wp #development db reset --yes
wp #production db export - > sql-dump-production.sql
wp #development db import sql-dump-production.sql
wp #development search-replace https://example.com http://example.test
else
exit 0
fi
when I run it I get:
./sync-production.sh
Do you solemnly swear that you have had fewer than 2 alcoholic beverages in the last hour and that you would really like to reset your development database and pull the latest from production? [y/N] y
Success: Database reset.
/usr/bin/env: ‘mysqldump’: No such file or directory
Success: Imported from 'sql-dump-production.sql'.
Error: The site you have requested is not installed.
When I run mysqldump
jasper#~/webdesign/example.com/site $ which mysqldump
/usr/local/bin/mysqldump
from the terminal it starts fine:
$ mysqldump
Usage: mysqldump [OPTIONS] database [tables]
OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help
Read env: mysql: No such file or directory after `wp import` and tried adjusting the $PATH and now have
echo $PATH
/usr/local/sbin:/usr/local/mysql/bin:/usr/local/sbin:/usr/local/sbin:/usr/local/sbin:/usr/local/sbin:/Users/jasper/.rvm/gems/ruby-2.3.3/bin:/Users/jasper/.rvm/gems/ruby-2.3.3#global/bin:/Users/jasper/.rvm/rubies/ruby-2.3.3/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/jasper/.composer/vendor/bin:/usr/local/bin:/Users/jasper/.rvm/bin:/Users/jasper/.composer/vendor/bin:/usr/local/bin:/usr/local/mysql/bin:/Users/jasper/.composer/vendor/bin:/usr/local/bin:/usr/local/bin/mysql:/Users/jasper/.composer/vendor/bin:/usr/local/bin:/usr/local/bin/mysql:/Users/jasper/.composer/vendor/bin:/usr/local/bin:/usr/local/bin/mysql:/Users/jasper/.composer/vendor/bin:/usr/local/bin:/usr/local/bin/mysql
In .bash_profile I have
alias ll='ls -lGaf'
export PATH="/usr/local/sbin:$PATH"
export PATH="$PATH:$HOME/.composer/vendor/bin"
export PATH=$PATH:/usr/local/bin
export PATH=$PATH:/usr/local/bin/mysql
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
###-tns-completion-start-###
if [ -f /Users/jasper/.tnsrc ]; then
source /Users/jasper/.tnsrc
fi
###-tns-completion-end-###
export PS1="\u#\w $ "
When I run wp #production db check things do connect and are fine. I also can connect to the database over ssh using the same username and password using SequelPro..
Any ideas why I still get no such file or directory for running mysql as part of this script?
What happens when you run env mysqldump command in shell? You can install and use strace for example and run the script or just the failing command like strace -F <command>. Maybe you will reveal more details about this error.
The remote server did (no longer) have mysql-client installed. Once I did apt install mariadb-client-10 things started working again:
wp #production db export sql-dump-production.sql
Success: Exported to 'sql-dump-production.sql'.
and I could also run:
./sync-production.sh
Do you solemnly swear that you have had fewer than 2 alcoholic beverages in the last hour and that you would really like to reset your development database and pull the latest from production? [y/N] y
Success: Database reset.
Success: Imported from 'sql-dump-production.sql'.
.........
I need to run MariaDB inside existing Docker container.
Building and installation works just fine, but when Docker executes
RUN mysql < init.sql
to load DB schema I get
Can't connect to MySQL server (111 Connection refused)
However when I run the container and execute
docker exec -it silly_allen /bin/bash -c "mysql < init.sql"
it works just fine.
What might be the problem?
Thanks!
EDIT: Here's part of Dockerfile related to DB.
FROM centos:7
WORKDIR /root
...
RUN echo "[mariadb]" >> /etc/yum.repos.d/MariaDB.repo
RUN echo "name = MariaDB" >> /etc/yum.repos.d/MariaDB.repo
RUN echo "baseurl = http://yum.mariadb.org/10.1/centos7-amd64" >> /etc/yum.repos.d/MariaDB.repo
RUN echo "gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB" >> /etc/yum.repos.d/MariaDB.repo
RUN echo "gpgcheck=1" >> /etc/yum.repos.d/MariaDB.repo
RUN rpm --import https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
RUN yum install -y MariaDB-server MariaDB-client
RUN yum clean all
RUN echo "[mysqld]" > /etc/my.cnf
RUN echo "bind-address=0.0.0.0" >> /etc/my.cnf
RUN /etc/init.d/mysql restart
ADD init.sql /root
RUN mysql < /root/init.sql
...
According to Docker's best practices, you should be having 1 container per process that you want to run.
Also, there's an official mariadb image which allows you to mount a directory as volume, that could contain SQL dumps. These dumps are auto-imported when the container gets created, so this might prove to be handy.
I'd suggest instead of having one very large dockerfile, you break it up in separate services with docker-compose
If you do however want to keep this the way it is, I'd suggest you move the ADD init.sql ... part to the top, and concatenate the server starting up part and the dump import, because each RUN command is a separate layer with Docker. So you'd need something like what's described in the answer of this StackOverflow question:
RUN /bin/bash -c "/usr/bin/mysqld_safe &" && \
sleep 5 && \
mysql -u root -e "CREATE DATABASE mydb" && \
mysql -u root mydb < /root/init.sql
So that the server initializes and the dump gets imported in one layer
From what I can see, you are trying to run mysql < init.sql before starting the database. The error shows that this command requires the database to be running.
To solve this problem, add a startup script into you container containing:
mysqld
mysql < init.sql
And change your Dockerfile CMD to call this script.
This way is right:
# cat Dockerfile
...
ADD init.sql /tmp
ADD initdb.sh /tmp
RUN /tmp/initdb.bash
CMD ["/usr/bin/mysqld_safe --datadir=/var/lib/mysql"]
And the script:
# cat dump/initdb.bash
#!/bin/bash
set -e
set -x
mysqld_safe --datadir='/var/lib/mysql' --user=root &
until mysqladmin ping >/dev/null 2>&1; do
sleep 0.2
done
mysql -e 'create database init;' && \
mysql init < /tmp/init.sql && \
echo "Successfully imported" && exit 0
I use the official MySQL docker image, and I am having difficulty exporting data from the instance without errors. I run my export like this:
docker run -it --link containername:mysql --rm mysql sh -c
'exec mysqldump
-h"$MYSQL_PORT_3306_TCP_ADDR"
-P"$MYSQL_PORT_3306_TCP_PORT" -uroot
-p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"
dbname'
| gz > output.sql.gz
However, this results in the warning:
"mysqldump: [Warning] Using a password on the command line interface can be insecure."
As the first line of the outputted file. Obviously this later causes problems for any other MySQL processes which are used to consume the data.
Is there any way to suppress this warning from the mysqldump client?
A little late to answer but this command saved my day.
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
I realise that this is an old question, but for those stumbling across it now I put together a post about exporting and importing from mysql docker containers: https://medium.com/#tomsowerby/mysql-backup-and-restore-in-docker-fcc07137c757
It covers the "Using a password on the command line interface..." warning and how to bypass it.
Run Following command on terminal
docker exec CONTAINER_id /usr/bin/mysqldump -uusername --password=yourpassword databasename> backup.sql
Replace the
CONTAINER_id. username, yourpassword
with specific to your configuration.
To get Container Id :
docker container ls
To eliminate this exact warning you can pass password in MYSQL_PWD environment variable or use other connection method - see http://dev.mysql.com/doc/refman/5.7/en/password-security-user.html
docker run -it --link containername:mysql --rm mysql sh -c
'export MYSQL_PWD="$MYSQL_ENV_MYSQL_ROOT_PASSWORD"; exec mysqldump
-h"$MYSQL_PORT_3306_TCP_ADDR"
-P"$MYSQL_PORT_3306_TCP_PORT" -uroot
dbname'
| gz > output.sql.gz
Here's how I solved this to dump a mysql db into a file.
I created a dump-db.sh file with the content:
# dump db from docker container
(docker exec -i CONTAINER_ID mysqldump -u DB_USER -pDB_PASS DB_NAME) > FILENAME.sql
To get the CONTAINER_ID list them: docker container list
Add run permissions to the script:
chmod o+x dump-db.sh
Run it:
./dump-db.sh
Remember to replace the CONSTANTS above with your own data.
I always create bash "tools" in my repo root with which I can repeat common tasks, such as database dumps. With bash, you can also load your .env file, so your credentials are not in a file in the repo, but just in your .env file.
#!/bin/bash
# load .env
set -o allexport; . ./.env; set +o allexport
# setup
TIMESTAMP=$(date +%Y-%m-%d__%H.%M)
BACKUP_DIR="dockerfiles/db"
CONTAINER_NAME="cp-db"
# dump
docker exec $CONTAINER_NAME /usr/bin/mysqldump -u$DB_USER --password=$DB_PASSWORD $DB_NAME> $BACKUP_DIR/dump__$TIMESTAMP.sql