back up sql on a mac - mysql

I am trying to back up a database from terminal on a mac for first time
I use Xampp for SQL
But trying to back up from terminal
Trying
myusername$ mysqldump planet > planethealth.sql
but getting
-bash: mysqldump: command not found
I access xampp with following command and no password
/Applications/xampp/xamppfiles/bin/mysql -u root -p
Please help, project due tonight

I'm not personally a mac user but you have to find the binary for mysqldump, looking at your xampp path it maybe in:
/Applications/xampp/xamppfiles/bin/mysqldump
But that is just a guess. If it is you could try:
/Applications/xampp/xamppfiles/bin/mysqldump -u root -p planet > planethealth.sql
Alternatively if the binary is not in that location you may have to go and install it.
Hope this helps, good luck with the project!

Related

MySQL - Can't connect to local MYSQL server...ERROR 2002?

Hi I've looked all over the internet to find an answer to this problem but nothing seems to work. I get the below problem when I try to log in to mysql on terminal in OSX El Capitan.
The server is running.
What should I do, I've spent 5 hours trying to figure this out before posting this. I cannot find the my.cnf file in /etc and I'm not sure what to do with it. Someone please help.
Edit:
I've downloaded and installed(just double clicking - no terminal) this:
When everything is installed and i go into /usr/local/mysql/bin/ and try mysql -u root -p I get the following error:
This is my my.cnf file in /etc:
When I do sudo /usr/local/mysql/bin/mysqld_safe I get this:
df -h returns this, could it be something to do with space?
If you feel more comfortable installing it through the GUI here is an instruction guide on how to do that.
http://dev.mysql.com/doc/refman/5.7/en/osx-installation-pkg.html
Make sure you install the MySQLStartupItem.pkg and MySQL.prefPane. After you have done that you can verify your installation by opening up Terminal and running:
cd /usr/local
hitting enter then typing:
ls
hit enter again and verify the existence of two directories, one will just be MySQL and the other will be MySQL-(version number you installed).
At this stage I would restart your computer and then on restart the mysql server will start up.
Once it's restarted fire up terminal window again and type this:
/usr/local/mysql/bin/mysql -u root -p
EDIT
Open your /etc/my.cnf file and edit these two configurations.
[mysqld]
socket=/var/mysql/mysql.sock
[client]
socket=/var/mysql/mysql.sock
Hope this helps.

Backup DB from MYSQL command prompt

I recently tried to put my web application and mysql database on the same virtual server. Now I receive a port error. In order to fix the port issue, I want to back up the database and reinstall WAMP. Since I can't get to the phymyadmin, I have to use the mysql command prompt to do a dump.
Would anyone happen to know the EXACT command to put in, if my username is root, I have no password, and the database name is dev? I've tried it multiple ways and I get an error saying that my syntax is wrong.
Thanks in advance.
You can use the following command provided you know the name of the database:
mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
Alternatively I would install the MySQL Workbench which can connect to your local database instance and provides a GUI to run the export: MySQL Workbench.
Unfortunately if you've uninstalled WAMP then MySQL might not be running anymore, and the above commands will not work because the utilities cannot see the database. If this is the case, try installing WAMP to a new directory and manually copying over the MySQL data files:
How to restore MySQL database from WAMP?
mysqldump -u root -p dev > devBackUp.sql
DOS batch file to export the database with date and time in the filename
FOR /f "tokens=1-8 delims=:./ " %%G IN ("%date%_%time%") DO (
SET dt=%%G%%H%%I_%%J_%%K
)
mysqldump -u root -p[root_password] [database_name]> [database_name]_%dt%.sql
pause

How To Export/Import Large Database On MAMP

How do I export/import large database on MAMP ? Using PHPMyAdmin does not work as it supposed to be.
It should be done via terminal as below.
In the terminal navigate to bin folder of MAMP using below command cd /Applications/MAMP/library/bin
Use this command to export the file ./mysqldump -u [USERNAME] -p [DATA_BASENAME] > [PATH_TO_FILE]. EG would be ./mysqldump -u root -p my_database_name > /Applications/MAMP/htdocs/folder_name/exported_db.sql
Line should appear saying Enter password:. Here enter the MySQL password. keep in mind that the letters will not appear, but they are there.
If you need to import use BigDump Which is a MySQL Dump Importer.
Turn on MAMP!
Then, for both operations, open the terminal and type:
EXPORTING:
/Applications/MAMP/library/bin/mysqldump -u [USERNAME] -p [DATABASE_NAME] > [PATH_TO_SQL_FILE]
Then type your password in prompter (default root) and press enter.
Example:
/Applications/MAMP/library/bin/mysqldump -u root -p my_database_name > /Applications/MAMP/htdocs/folder_name/exported_db.sql
IMPORTING (will erase current database):
/Applications/MAMP/library/bin/mysql -u [USERNAME] -p [DATABASE_NAME] < [PATH_TO_SQL_FILE]
Then type your password in prompter (default root) and press enter.
Example:
/Applications/MAMP/library/bin/mysql -u root -p my_database_name < /Applications/MAMP/htdocs/folder_name/exported_db.sql
/!\ Important Warning: Make sure to backup your current database before doing this command in case you need a copy of it before importing. This will erase your current database!
You can also use the Sequel Pro App if you are using MAMP PRO version to get around the defaults that phpMyAdmin gives you.
I had a problem to dump my db from MAMP. Tried a lot of things, but always this error:
Got error: 2002: Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock'
Tried to create a symlink, but it was already created "ln: /tmp/mysql.sock: File exists"
Thought the problem was new Mac or new MAMP.
Finally in my case (problem was in me) solution was really simple: just turn on MAMP :)
Maybe it will help someone to save a little bit time (I spent around 4 hours)

Mysql command not found in OS X 10.7

I cant get my mysql to start on os x 10.7. It is located in /usr/local/mysql/bin/mysql
I get command not found when I type mysql --version in the terminal.
I tried this can't access mysql from command line mac but still get command not found. I tried installing mysql with the dmg and i have tried to install it through homebrew and I cant get it to work. When I try to start mysql with homebrew I get MySQL won't start
This is my $PATH:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin:/Users/Victoria/bin:/usr/local//usr/local/mysql/bin/private/var/mysql/private/var/mysql/bin
This is the problem with your $PATH:
/usr/local//usr/local/mysql/bin/private/var/mysql/private/var/mysql/bin.
$PATH is where the shell searches for command files. Folders to search in need to be separated with a colon. And so you want /usr/local/mysql/bin/ in your path but instead it searches in /usr/local//usr/local/mysql/bin/private/var/mysql/private/var/mysql/bin, which probably doesn't exist.
Instead you want ${PATH}:/usr/local/mysql/bin.
So do export PATH=${PATH}:/usr/local/mysql/bin.
If you want this to be run every time you open terminal put it in the file .bash_profile, which is run when Terminal opens.
One alternative way is creating soft link in /usr/local/bin
ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
But if you need other executables like mysqldump, you will need to create soft link for them.
I faced the same issue, and finally i got a solution. Please go through with the below steps, if you are using MAMP.
Start MAMP or MAMP PRO
Start the server
Open Terminal (Applications -> Utilities)
Type in: (one line)

 /Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot
This works for me.
If you installed MySQL Server and you still get
mysql -u root -p command not found
You're most likely experiencing this because you have an older mac version.
Try this:
in the home directory in terminal open -t .bash_profile
paste export PATH=${PATH}:/usr/local/mysql/bin/ inside and save it
instead of writing mysql -u root -p paste the following in your terminal:
/usr/local/mysql/bin/mysql -u root -p
Or use Alias instead of writing the full path
alias mysql=/usr/local/mysql/bin/mysql
Enter your password. Now you're in.
You have to set PATH for mysql in your .bashrc file using following:
export PATH=$PATH:/usr/local/mysql/bin
But If you are using oh my zsh then you have to add path inside .zshrc file.
Your PATH might not setup. Go to terminal and type:
echo 'export PATH="/usr/local/mysql/bin:$PATH"' >> ~/.bash_profile
Essentially, this allows you to access mysql from anywhere.
Type cat .bash_profile to check the PATH has been setup.
Check mysql version now: mysql --version
If this still doesn't work, close the terminal and reopen. Check the version now, it should work. Good luck!
Use these two commands in your terminal
alias mysql=/usr/local/mysql/bin/mysql
mysql --user=root -p
Then it will ask you to enter password of your user pc
Enter password:
I have tried a lot of the suggestions on SO but this is the one that actually worked for me:
sudo sh -c 'echo /usr/local/mysql/bin > /etc/paths.d/mysql'
then you type
mysql
It will prompt you to enter your password.
Add the following lines in bash_profile:
alias startmysql='sudo /usr/local/mysql/support-files/mysql.server start'
alias stopmysql='sudo /usr/local/mysql/support-files/mysql.server stop'
and save the bash_profile.
Now, in the terminal start and stop the mysql server using the following commands:
startmysql //to start mysql server
and
stopmysql //to stop mysql server
If you are using terminal you will want to add the following to ./bash_profile
export PATH="/usr/local/mysql/bin:$PATH"
If you are using zsh, you will want to add the above line to your ~/.zshrc
With MAMP
Locate mysql usually at /Applications/MAMP/Library/bin/mysql
sudo vi /etc/paths
Add this path to file /Applications/MAMP/Library/bin
:wq (Save and quit file)
Close Terminal windows
Reopen Terminal and type mysql and it should work
I installed MAMP and phpmyadmin was working.
But cannot find /usr/local/bin/mysql
This fixed it
sudo ln -s /Applications/MAMP/Library/bin/mysql /usr/local/bin/mysql
in terminal do:
vi ~/.bash_profile
And add this line:
export PATH=${PATH}:/usr/local/mysql/bin
and the type this in terminal:
mysql -u [username] -p [password]
Maybe I'll help someone else. None of the above answers worked for Catalina. Finally, this solved the problem
echo 'export PATH="/usr/local/opt/mysql#5.7/bin:$PATH"' >> /Users/$(whoami)/.bash_profile
Of course, you have to change for the version of mysql you have installed
May be i will help out some of you that even though if you are unable to open mysql from terminal after trying changing path in .bash_profile
then you always found the error "MYSQL not found"
hence you can use the following command directly it will ask for your password and sql bash is opened
/usr/local/mysql/bin/mysql -u root -p
I had same issue after installing mariadb via HomeBrew, brew doctor suggested to run brew link mariadb - which fixed the issue.
It is possible you are using zsh instead of bash then you have to enter the above mentioned commands in .zshenv instead of .bash_profile

Add mysqldump to MAMP (MySQL /w Apache PHP on MacOS X)

I wonder how I can add mysqldump to my MAMP environment. I googled a bit and found only the community MySQL server version. But I do not want to install another MySQL – basically because I want to save my data first, before any experiment.
Found the solution on my own. Maybe this helps other Mac users...
In fact mysqldump ships with MAMP but is located somewhere in the desert:
/Applications/MAMP/Library/bin/mysqldump
That´s why tools like MySQL workbench do not find it, neither does it work in terminal without the path. So finally just type:
/Applications/MAMP/Library/bin/mysqldump -u yourUser -p --opt yourdb > yourdump.sql
to create a dump.
In .bash_profile, add PATH="$PATH:/Applications/MAMP/Library/bin".
If you don't have a .bash_profile, you can create one.
I've recently discovered that MAMP PRO hides all your mysql terminal abilities.
Using this though copies all the mamp Mysql magic over to your local bin, where you can start using all wp-cli db functions again or anything that you need with databases via terminal:
sudo ln -s /Applications/MAMP/Library/bin/mysql /usr/local/bin/mysql;
sudo ln -s /Applications/MAMP/Library/bin/mysqlcheck /usr/local/bin/mysqlcheck;
sudo ln -s /Applications/MAMP/Library/bin/mysqldump /usr/local/bin/mysqldump
This will helps you to resolve:
In your home directory create or edit the file .bash_profile you can access your home directory by typing: cd ~/
Add this to the top of the file:
export PATH=$PATH:/Applications/MAMP/Library/bin
Save the file and then restart your Terminal
In your newly restarted Terminal window type: mysql –version
/usr/local/mysql-5.6.20-osx10.8-x86_64/bin/mysqldump -u root -p databasename tablename > /Library/WebServer/Documents/upload/kg_exam_metadata.sql;