Installing MySQL on a mac - mysql

i have downloaded and installed mySQL my double clicking on its icon. It was installed successfully.
When i goto startup and preference i see the icon of mysql added and when i click on it i see a screen where it says 'MySQL server instance is running'.
But when i open terminal and cd to /usr/local/mysql and then when i type sudo ./bin/mysqld_safe i was prompted for a password. and i have not added a password when i installed mySQL, so i tried leaving it blank, and then i tried various passwords to login but all attempts failed.
So now i need to know how to login to mySQL via the terminal ?
mysql version - 5.5.24-osx10.6x86_64
my Mac OS - 10.7.3

What I found installing mysql on MacOs, there are a few differences. One is that it installs it without a password. The other thing is that it by default allows for anonymous logins.
Use this to set the password:
mysqladmin -u root -h localhost password yourpassword
You can remove anonymous logins this way:
shell> mysql -u root -p
Enter password: (enter root password here)
mysql> DROP USER ''#'localhost';
mysql> DROP USER ''#'host_name';
The other thing is that I found that the install does not modify the path variable. What I did to run mysql from the command line was to add /usr/local/mysql/bin to path by adding it to /etc/paths or /etc/paths.d . This may be what you need in order to run mysql. Like someone said in the comments, mysqld_safe is one way to start the mysql server, and it seems that is already set to run.
Here are specific instructions to add something to /etc/paths.d
$ cd /etc/paths.d
$ cat > mysql
/usr/local/bin/mysql
(and then type Ctrl-D
that should put a file there)
you may have to sudo if you do not have permissions.

The sudo command, by default, lets anyone in the admin group run a command as root by giving his own password. That's why it asked for your password when you typed "sudo ./bin/mysqld_safe". It has nothing whatsoever to do with mysql.
If you don't have a password, you cannot use sudo in the default configuration. Either give yourself a password, or edit the sudoers file. (I would strongly suggest the former over the latter, especially if you have no idea what sudo does.)
For more information, type "man sudo" (and then "man sudoers") from your Terminal.
Meanwhile, the reason "it says -bash: mysql: command not found when i type mysql in the terminal" is because you've clearly installed it into /usr/local/mysql/bin/mysql, and that isn't on your path. If it were on your path, you could have just done "sudo mysqld_safe" above, instead of "sudo ./bin/mysqld_safe". Since it's not, you have to do "./bin/mysqld_safe".
For more information, consult a good primer on the Unix shell.
Finally, if you've got the mysql daemon running, and are trying to start the client, it's "mysql" that you want to run, not "mysqld_safe".

Related

Issue with mysqldump returning Permission denied

I'm trying to setup a backup system for MySQL from PHP by using mysqldump command but I'm having a Permission denied error.
I'm on MacOS Catalina 10.15.6, using system PHP and Homebrew mysql#57.
After many attempts, I could reproduce this issue in Terminal. If I run the command as me, it works fine and the backup file is correctly created, but when I run it as _www I get the error.
This works:
% mysqldump --defaults-extra-file="crd" --extended-insert mydb > backup.sql.gz
And this does not work:
% sudo -u _www mysqldump --defaults-extra-file="crd" --extended-insert mydb > backup.sql.gz
sudo: unable to execute /usr/local/opt/mysql#5.7/bin/mysqldump: Permission denied
I checked and mysqldump can be executed by user, group and other:
% ls -la /usr/local/opt/mysql#5.7/bin | grep mysqldump
-r-xr-xr-x 1 jbogdani staff 3853364 Aug 17 21:22 mysqldump
Other attempts to provide username and password in the command also fail.
mysqldump will need a password for the mysql user root. If you don't supply that password it won't work, sudo or no sudo.
instead of using sudo -u _www just execute it with current mysql user account.
if you need further reading
You need to use a full path on the output.
You do not have permissions to write to /usr/local/opt/mysql#5.7/bin/backup.sql.gz. Specify full path of the target backup archive to another directory
I think you'll find the _www user is restricted in some way. It might not have a valid shell, it might be locked, or there might be apparmour/selinux restrictions preventing it from running.
Check the output of dmesg and /var/log/secure for useful logs, otherwise check and change the shell and status of the user using usermod to find and isolate the issue.
Make sure you consider the security ramifications before doing anything in production though.

MySql Command not found : MacOS

I'm new to using the terminal and I'm having trouble troubleshooting the following issue:
After looking at some other similar problems I've tried the following commands that might enlighten you to what is wrong.
First I'll post a summary of the things I've tried in the terminal and the responses I got from the terminal. Below that I'll "briefly" write about installation process and workbench issue.
(MyUserName)$ sudo ln -s /usr/local/mysql/bin/mysql usr/local/bin
Password:
(I input my Mac password here)*
ln: usr/local/bin: No such file or directory
Sometimes I get "No such file or directory" but sometimes I get the following:
(MyUserName)$ sudo ln -s /usr/local/mysql/bin/mysql /usr/local/bin
ln: /usr/local/bin: File exists
I still can't access mysql though, even if I try straight after the "File Exists" reply.
Perhaps I messed something up yesterday when I did the above command but forgot the "s" after the dash?
(MyUsername)$ ls /usr/local/mysql
LICENSE README bin data docs include keyring lib man share support-files
(MyUsername)$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local//bin
Something I tried because of similar questions*
(MyUsername)$ export PATH=$PATH:/usr/local//bin
I just got another prompt from the terminal and tried the following login after that:*
(MyUserName)$ mysql -u root -p
-bash: mysql: command not found
I have successfully installed mysql and workbench and used it with no problem, however I just factory reset my MacBook and when installing again, I'm having these problems.
At first I noticed that the default shell in the terminal was zsh, and I changed it to be default bash because I wasn't sure the commands were the same, and I am learning from a video and he uses the bash shell.
When installing mysql, I was not allowed to change the path or change where it was installed, not that I would've done so, but perhaps that's weird?
I also did not get to choose anything else except the type of password and then setting the password. (I remember choosing which components or something when doing this before)
In workbench, my root server says it's running, when I try to make another connection everything seems normal except that there is no input field for the password. So I've tried making the connection anyway but when trying to use it, it asks me for a password, where my root password does not work.
I appreciate all the help I can get, I need this for my studies (Teacher couldn't help due to the OS). Please let me know if you have any suggestions, thanks :)!
Your command should have been:
sudo ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
Basically, the command does a symbolic link for the mysql binary in /usr/local/bin which is already in your search path.
Alternatively you could have added '/usr/local/mysql/bin/mysql' to PATH

mysql command line client for linux

I just installed mysql 5.6 in a new CentOS 7 linux installation. I want to use the mysql command line client that I have been used to using in windows, but I cannot seem to find it. Is there a mysql command line client for linux? If so, how do I make sure that I have it? And how do I open it up in the GUI?
You can open MySql command line utility using following command
mysql -u user_name -p
It will ask for password for user_name. If password is not set call as follows
mysql -u user_name
First make sure the service is running :
sudo systemctl start mysqld
Then make sure to run the security script that will remove some dangerous defaults and lock down access to our database system a little bit.
sudo mysql_secure_installation
Now you can use the command line tool
mysql --user=user_name --password=your_password db_name

Cannot connect to MySQL Workbench on mac. Can't connect to MySQL server on '127.0.0.1' (61) Mac Macintosh

Cannot connect to MySQL Workbench on mac. I get the following error: Could not connect, server may not be running. Can't connect to MySQL server on '127.0.0.1' (61)
The help would be appreciated.
Thank You!
Ran into a similar issue and my problem was that MySQL installed itself configured to run on non-default port. I do not know the reason for that, but to find out which port MySQL is running on, run the following in MySql client:
SHOW GLOBAL VARIABLES LIKE 'PORT';
Go to System preferences -> MySql and check the state of your MySql instance.
There may be one or multiple reasons if you are not able to connect to MAC OS X MySQL server with MySQL-workbench.
When you press 'test connection' you might see this error. This could be explained briefly if you go step by step through 'Configure server management..'
On the basis of the red crosses you can filter out the real problem.
The most common problems are associated with the installation of MySQL-server. Few people either forget to install the server prior to installing MySQL-workbench. Some others would install a part of the product. Please check whether you have also installed all the 3 parts that comes with the MySQL-Server dmg(disk image) file which contains mysql-server package. Those 3 parts are: MySQL server, preference pane and startup item.
Note: If you haven't selected preference pane then you won't be able to start mysql server instance from the System preferences.
After you make sure that you have installed each item then you can check server instance of your native mysql-server. Open System preferences from dock and click MySQL. Then click Start MySQL Server to start the server instance. If the server instance is stopped, then MySQL-workbench won't be able to connect to the MySQL server.
If you are still facing issue, then you need to check the port of the connection which you are making. Default port is '3307' and NOT '3306'. You can check it with using the following command in mysql terminal:
SHOW GLOBAL VARIABLES LIKE 'PORT';
Please note that this process helps you to connect to the local instance. If you have to connect to a remote server, then you have to enter that specific IP and Port. Contact your server's administrator if you are facing the issue. As this question specifically states that the problem is related to connecting to the local instance, I am not writing checks that you may need to ensure.
This steps are all in the terminal:)->source
Step make sure your server is running:
sudo /usr/local/mysql/support-files/mysql.server start
Check MySQL version. "This also puts you in to a shell interactive dialogue with mySQL, type q to exit."
/usr/local/mysql/bin/mysql -v
Make your life easier: "After installation, in order to use mysql commands without typing the full path to the commands you need to add the mysql directory to your shell path, (optional step) this is done in your “.bash_profile” file in your home directory, if you don’t have that file just create it using vi or nano:"
cd ; nano .bash_profile
paste in and save:
export PATH="/usr/local/mysql/bin:$PATH"
"The first command brings you to your home directory and opens the .bash_profile file or creates a new one if it doesn’t exist, then add in the line above which adds the mysql binary path to commands that you can run. Exit the file with type “control + x” and when prompted save the change by typing “y”. Last thing to do here is to reload the shell for the above to work straight away."
source ~/.bash_profile
mysql -v
"You will get the version number again, just type “q” to exit."
Check out on which port the server is running:
in your terminal type in: mysql
and then
SHOW GLOBAL VARIABLES LIKE 'PORT';
use everytime a semikolon in the mysql client (shell)!
now you know your port and where you can configure your server(in the terminal with mysql shell/client). but for a successful connection with MySQL Benchmark or an other client you have to know more. username, passwort hostname and port. after the installation the root user has no passwort so set(howtoSetPW) the passwort in terminal with mysql shell/client. and the server is running local. so type in root, yourPW, localhost and 3007. have fun!
Try restarting the mysql or starting it if it wasn't started already. Type this within terminal.
mysql.server restart
To auto start go to the following link below:
How to auto-load MySQL on startup on OS X Yosemite / El Capitan
In my case I had a previous mySQL server installation (with non-standard port), and I re-installed to a different directory & port. Then I got the same issue (in windows). To resolve, you click on home + add new connection.
If you need to know the port of your server, you can find it when you start My SQL command line client and run command status (as below). In windows it is via All Programs -> MySQL -> MySQL ServerX.Y -> MySQL X.Y Command Line Client
I had the same issue, I solved this with the following steps:
Install the MySql (DMG) from this link
If the mysql package comes with the file name "mysql-5.7.13...." and
"MySql.prefPane" then your life is really easy.
Just click on "mysql-5.7.13...." and follow the instructions.
After the installation is done, click on "MySql.prefPane" and checkout "Only
for this user" in the popup. We use "MySql.prefPane" to start the mysql
server as this is really imp because without this you will end up having
errors.
Click on Start MySql Server in the next dialog box.
OR
If you don't see "MySql.prefPane" in the package then follow these steps:
Click on package "mysql-5.7.13...." and this will show you one password as
soon as installation is done. That password is use to start the connection.
You can change it. I will let you know in a while.
After installation save the password (this is really important - you'll need it later), open terminal.
$ cd /usr/local/mysql/bin/
$ ./mysql -u root -h localhost -p
And then type the password from above. This should start mysql>
To change the password:
$ cd /usr/local/mysql/bin/
$ ./mysqladmin -u root -p password 'new_password'
Enter Password: <type new password here>
$ ./mysql -u root -h localhost -p
... and log in with the new password.
After this you can go to MySql workbench and test connection. It should connect.
brew services start mysql defualt set --bind-address=127.0.0.1 with /usr/local/Cellar/mysql/5.6.27/homebrew.mxcl.mysql.plist,so replace --bind-address=127.0.0.1 with --bind-address=* or --bind-address=0.0.0.0
for mac : check the compatible version of mysql server in workbench>preference>MySql
if it's the same version with your mysql server in: cd /usr/local/
I am using those commands on MacOs after getting the same error
sudo /usr/local/mysql/support-files/mysql.server start
sudo /usr/local/mysql/support-files/mysql.server stop
sudo /usr/local/mysql/support-files/mysql.server restart
I had the same problem. I removed mySQL completely, and reinstall it using homebrew.
I had same problem, but it worked for me.
check if you have mysql installed
If you don't have mysql installed, download from this link: https://dev.mysql.com/downloads/mysql/
follow this instructions to install
https://dev.mysql.com/doc/mysql-osx-excerpt/5.7/en/osx-installation-pkg.html
You can test the connection without any problem.
(Sorry for my english, I agree fix me please)
I Hope I've helped.
Greetings.
I ran into the same scenario
I opened "System Preferences", clicked "MySQL", then clicked "Initialize Database" button. I entered a new password and saved it in a safe place.
After that i restarted the MySql Instance (in the System Preferences dialog as well).
After that i opened MySqlWorkbench and opened the default connection, entered the password i set before and: Viola, i can do whatever i want :-)
I had this same issue on Monterey. Make sure you're selecting the correct download according to your processor architecture.
Community download processor architecture
Also, for the Connection Method use the Local Socket/Pipe
connection method
Dropping this to share my experience.
I had the same problem and realise I didn't start MySql server.
The steps below shows how I was able to login:
To start your server, Go to Preference and find MySql.
Click on the instance tab to start the server
Afterward, return back to Mysql Workbench to start the Local Instance and you'll be connected.
Have fun !
I had similar issues in Mac OS Catalina and the easiest way to solve it is by downloading HOMEBREW package manager for mac. Follow the steps to install HOMEBREW and mysql server.
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew install mysql
$ brew tap homebrew/services
$ brew services start mysql
mysqladmin -u root password 'yourpassword'
Now try using mySQLworkbench it should work.

how to run mysql v5.5 on redhat linux

I am new to both linux and also mysql but somehow by obtaining help from net I have installed mysql v5.5 on redhat. It starts fine, I have confirmed this by running command:
"/etc/init.d/mysqld status"
But I am not able to change password using command:
mysqladmin -u root password 'new-password'
It gives error : bash: mysqladmin: command not found.
I tried searching mysqladmin by using command "find / -name mysqladmin" but it returned no result
All I can search on net is adding to path '/bin:/usr/local/mysql/bin' but directory structure after installation mysql v5.5 has changed. There is no such directory like /usr/bin/local/mysql now.
please help me with how to run mysql after changing root's password.
first of all see what MySQL packages are installed
rpm -qa | grep -i mysql
Second, try using locate in order to find the tool path
BTW,
According to pbone mysqladmin is provided by mysql-client (rather than mysql) as it was on older cackeages