I'm running macOS Mojave, just installed MySQL using the official installer. I can start/stop the server without problem from the Preference pane.
But from the command line I always get Permission denied trouble:
$ mysql.server start
Starting MySQL
./usr/local/mysql/bin/mysqld_safe: line 144: /usr/local/mysql/data/mysqld.local.err: Permission denied
/usr/local/mysql/bin/mysqld_safe: line 144: /usr/local/mysql/data/mysqld.local.err: Permission denied
/usr/local/mysql/bin/mysqld_safe: line 199: /usr/local/mysql/data/mysqld.local.err: Permission denied
/usr/local/mysql/bin/mysqld_safe: line 144: /usr/local/mysql/data/mysqld.local.err: Permission denied
ERROR! The server quit without updating PID file (/usr/local/mysql/data/mysqld.local.pid).
I also tried with the mysqld and mysqld_safe commands with the same results.
The owner of the data directory is the _mysql user:
$ ls -l mysql/
drwxr-x--- 42 _mysql _mysql 1344 Nov 5 21:14 data
I would do su _mysql 'mysql.server start' for example, but I don't know the password of _mysql if it has any, I think it's not a login account.
So how can I start the server from the command line?
Update
As the official MySQL documentation explains here, to run the server as normal user you have to own the data directory recursively works:
$ chown bob -R /usr/local/mysql/data
I can start/stop the server from the command line, using any of the commands above, and connect to the server as well.
Problem is, now it doesn't work the Preference pane!
Now the question is: Is there any way of getting back the Pref pane working? Most importantly, why did that happen?
mysqld_safe is just a wrapper for the mysqld command that will start for you your mysql server with the correct user.
However, you should have to run it with sudo. If you find or manage to replace the password for your mysql user, you might be able to use directly the mysqld command.
So, a quick way to start your server is: sudo mysqld_safe.
Further details can be found on MySQL documentation: Starting the server
So no, the solution can't be found in start MySQL server from command line on Mac OS Lion, but it can be found here
Basically in that post they explain that the pid file used by the launchd service (the pref pane uses that service) has a different name of the one that msqld uses:
The Preference pane call it mysqld.local.pid
msqld calls it the_name_of_your_localhost.local.pid
So if you start the server from the pane you mess the name of the pid file, and then the commands get confused because it looks for a pid file named differently. And the other way around.
We can find the same naming trouble with the error log file.
Also I found out that the names for the socket files are also different:
/tmp/mysql.sock for the commands
/tmp/mysqlx.sock for the service/pane
Maybe there's a way using configuration files to use unified names, but I couldn't make it work. At least now I understand the problem, although don't know how to fix it. In the meantime I'll have to to choose: either the command line or the preference pane, but not both. They are incompatible ;-)
I start the mysql :
mysqld_safe --user=_mysql
and I create a file which blongs to root:
-rw-r--r-- 1 root staff 0 12 4 19:40 a
and exec:
mysql> system rm /home/test/a
and the file was deleted。
has anyone kown how to make 'system' command unavailable when the mysql account which is specified by 'mysqld -u' are different to the account of system(file or others)
The system command in the mysql client command line program doesn't run commands on the MySQL server machine. (If it did, can you imagine how easy it would be for cybercriminals to pwn IT infrastructure?)
It runs them on the same machine upon which you are running mysql.
The mysql command ordinarily runs with the same user and set of permissions as the shell program that invoked it. So, anything users could do with mysql system they could also do in the shell used to run it.
Therefore, disabling the mysql system command is unnecessary and insufficient for tightening system security.
(Users without shells are another story. If you have those kinds of users, you probably should disable the system command.)
If you don't trust the user who must run the mysql client you'll need to grant them a limited environment. You can look up chroot for that.
Pretty simple question here. I just want a SQL database on my version of Kali linux so I can practice SQL.
I opened the command line and entered tried to start mysql and get an error.
> mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
I also made sure it was already installed using apt-get.
What are the steps I need to take to be able to make a database with tables and data that I can query?
I don't know about Kali, but on Ubuntu it would be
$ sudo service mysql start
Once that command returns, the mysqld service has started, so you can use the mysql client to connect to it.
Of course, you also have to make sure you have the mysql-server package installed, not just mysql-client and mysql-common, and that you've initialized the database instance. Complete post-installation instructions can be found in the official documentation, but the short version is
Make sure the installer has created the mysql user account. This is the account that will "own" the server process once it starts.
Change to your data directory. (I used the installer's default of /var/lib/mysql; you can change this by editing my.cnf.)
As root, execute the server daemon with the --initialize switch. Check whereis to determine the correct path, then
$ sudo /path/to/mysqld --initialize --user=mysql
This command will twiddle itself for a while, then display an automatically-generated password and exit. Once the command returns, the database instance has been initialized and the system tables created. You can now start the database instance normally (using service start), then log in as the database user root (which is not the same as the system user root) using the password from above, then change your password, create a new database user, log in as that user, create a user database, and start creating tables.
Again, the official documentation is the place to look for this; if any of the instructions in the official documentation differ from my instructions, you should ignore me and follow the official documentation's instructions.
If sudo service mysql start doesn't work for you, please try running mysqld_safe and don't kill the process. Use another tab to check the status of mysql service. This should solve your mysqld.sock issue.
If it doesn't work out, then please edit your my.cnf file and add the following:
socket=/var/lib/mysql/mysql.sock
And the permissions,
sudo chmod -R 755 /var/lib/mysql/
Hopefully, this should do it.
On my version of kali (2022-rolling), even though it's installed as MySQL, it's run as mariadb. To start it is:
sudo /etc/init.d/mariadb start
Try this
sudo service mysql start
I installed MySQL on Microsoft Windows 8 Using a noinstall Zip Archive. But when I tested by executing the following commands on windows prompt, the above error showed up.
C:\> "C:\MySQL\bin\mysqlshow"
C:\> "C:\MySQL\bin\mysql" test
You don't need to restart your windows. The easiest way to achieve this is
Go to <Extracted folder location>/bin/
Run mysqld (service)
close the cmd prompt
Run mysql.exe or the better way to do is add the location to PATH environment Variable
Go to Run type services.msc. Check whether MySQL services is running or not. If not, start it manually. Once it started, type mysqlshow to test the service.
Go to bin directory copy the path and set it as a environment variable.
Run the command prompt as admin and cd to bin directory.
Run command : mysqld –install
Now the services are successfully installed
Start the service in service windows of os
Type mysql and go
Though it is an old question, I am adding my answer in it, because the solution that worked for me on Windows 7 as an admin user, is missing in the answers' list. Though my solution is for installed MySQL, I am putting it for those who search for a solution for this error message. Here it is:
Click on the Windows 7 start button and type taskmgr in the search bar
Right click on the taskmgr program icon and select Run as administrator
In the Task Manager window, go to the Services tab
Right click on the MySQL service and click Start Service
The solution that worked for me is:
Downloaded mysql-8.0.22-winx64.zip file
Extracted the zip file
Moved the extracted folder to C:/Program Files
Opened cmd.exe as admin
Navigated to the directory cd C:\Program Files\mysql-8.0.22\mysql-8.0.22-winx64\bin
mysqld -install (Service successfully installed)
mysqld --initialize (no prompt)
Opened services.msc
Found MySQL
Right-click and start
I was stuck on this same issue for what felt like an eternity.
My problem was: I was running mysql from MAMP on port 8889, but when trying to connect to mysql from my command line, it was expecting port 3306. I was running out of ideas, so I tried:
mysql --port 8889
and happiness ensued:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.34-log MySQL Community Server (GPL)
Go to Run type services.msc. Check whether MySQL services is running or not. If not, start it manually.
Run your cmd as administrator.
What you will see is like this:
c:\windows\system32>
Go to your bin location by using cd..
like C:\mysql\bin (my location of bin in my computer is what you are seeing so chose yours correctly)
Run:
$ C:\mysql\bin>mysql --install
Service successfully installed.
Then run:
$ C:\mysql\bin>NET START MySql
The MySql service is starting
The MySql service was started successfully
Then the last step is running:
C:\mysql\bin>mysql -u root - p admin
It will ask for password don't enter anything first time
because it will use blank, and just press enter you are done.
And later you can set password too.
I have a windows 8.1 machine and mysql was not running at all even after trying to start mysqld with no error logs. This solution worked for me:
start cmd in admin mode
type in "net start mysql"
close current cmd window and open new cmd window
type in "mysql"
The mysqld service should now be available.
Had this issue in Windows 10 and MySQL 8. Resolved by following steps:
Searchbar(bottom left) > Task Manager > Run as administrator > Services > MySQL80
Well that could have some reasons.
THe first one is that the MySQL server/service not started.
If he is started you should check out the logfiles, and make sure there are no problems.
You could also uninstall the MySQL service and install XAMPP.
With XAMPP it is easier to manage this services.
Despite that my server was running, I had the same problem.
I found out that it was the port. So you need to specify the port:
mysql -u user -p --port 0000
The port on your machine may be different. To find out on which port mysql is running open the mysql ini file and look for port=. A port often used is 3306.
Example how to log on to mysql
mysql -u root -p --port 3306
Test if the server is running. You can use netstat for this. See https://serverfault.com/questions/260239/unable-to-connect-to-mysql-through-port-3306
If it is running, it may be the firewall. You can turn that off to test if that is the problem.
See the following manual to install Mysql as a service: https://dev.mysql.com/doc/refman/5.5/en/windows-start-service.html
First of all, you need to ensure the port number on which the server is running. Then you can run
mysql -u username -p --port portNumber
on the command line
Executing the mysqld command can solve your problem.
My SQL version is 5.7.
If you're using the no install zip, you need to execute mysqld.exe first to start the service, and then execute mysql.exe to open your connection.
The no install is nice, but if you intend to do any serious work with MySQL, you may want to consider either using the MSI to do a proper installation, or if you're doing web development work give XAMPP a try.
Check Mysqld.exe file is in your bin folder. if it is not there , just copy that file from any other computer and paste it on your bin folder.Just double click. Then run mysql.its solved
This error is flashed when we are trying to open mysql with out stating the service.
Open cmd prompt
to start the service type
mysqld --console
This will start the mysql service
Don't close this cmd prompt and open a new cmd prompt and
type
mysql -u root -p
Then enter ur password
Make sure your mysql is running in default port (3306) , if you are running mysql with different port (for example: 3307), you must specified the port number while connecting to the server.
If your port is different than default port, then try with this command.
mysql -u <username> -p --port<port number>
For eg:
mysql -u root -p --port 3307
Go and search Services in Windows
Now search Mysql. Right Click on it. By Default it's startup type will be 'Automatic'. Click on Properties on right clicked menu.
You will find startup type Switch it to -> Manual So that We can start and stop by our choice.
Now Get Back and Right Click to Mysql on Services and Click Start.
Now Mysql has started successfully
To get started
Start Mysql Shell
& type command
shell.connect({host: 'localhost',user: 'root'})
Now type password
To type sql commands:-
/sql
I had the same problem. I tried all of the answers above (and some from other websites). In the end, my issue was that my cache wasn't configured. I found that info in my error log and fixed it by changing the line in the file:
C:\MAMP\bin\apache\conf\extra\http-ssl.conf
There I removed the double quotes from the line:
SSLSessionCache "shmcb:/some/example/path/ssl_scache(512000)"
to:
SSLSessionCache shmcb:/some/example/path/ssl_scache(512000)
and saved with Ctrl+S and closed the file.
Here's the link that helped me:
https://wiki.apache.org/httpd/SSLSessionCache
I faced the same problem couple of times and each time the reason was different:
The solution that worked first time was that by "Abhishek Oza" which is same as that of "amey91" (see above)
The second time, my server was on a different port number than the default one(3036),so i was not able to connect.So I had to specify
the port number explicitly for making the connection which you can do
simply by writing: "mysql --host=127.0.0.1 --port=8081(specify your
port number here) mysql -u root -p"
In my case, which was a manual install using the .zip file.
I solved this by specifying the nonstandard MySQL and Data install locations in a my.ini.
https://dev.mysql.com/doc/refman/8.0/en/windows-create-option-file.html
Then I needed to run the data directory initialisation commands:
https://dev.mysql.com/doc/refman/8.0/en/data-directory-initialization-mysqld.html
Then running:
net start mysql
There is a possibility that your installation of MYSQL got corrupted. The best thing you can do is to search for MYSQL INSTALLER on your system and then run it again.
It will not download the mysql server again, it will just help you to set it up.
After that, edit your environment variables path and add the bin folder of your mysql to it.
By now, it should work.
In my case I have 2 different version of mysql in Windows OS and I solved the my problem by bottom step:
first stop all mysql service.
I create one config file in C:\mysqldata.cnf with bottom data(my mysql is in "C:/mysql-5.0.96-winx64" directory ):
[mysqld]
datadir = C:/mysql-5.0.96-winx64/data
port = 3307
then I run bottom command in cmd:
C:\mysql-5.0.96-winx64\bin\mysqld --defaults-file=C:\mysqldata.cnf --console
above step reference
then I create txt file in C:\resetpass.txt with bottom data:
UPDATE mysql.user SET password=PASSWORD('ttt') WHERE user='root';
then run mysqld with bottom command:
C:\mysql-5.0.96-winx64\bin\mysqld --init-file=C:\resetpass.txt --install mysql2 --console
net start mysql2
after these step you have one mysql service(with name mysql2) than run with port 3307.
I have 2 version of mysql with different user management tables(in version 5.0.96 user table difference with 5.5 version because of that I must be change table folder in first step)
you can run other mysql service with other port now(and you can run this steps with different datadir, service name and port for it again)
First make sure you have installed MYsql+Sqlyog(if you are using it.).
Start Registry Editor (Regedt32.exe).
Locate the following key in the registry:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
On the Edit menu, click Add Value, and then add the following registry value:
Value Name: MaxUserPort
Data Type: REG_DWORD
Value: 65534
This sets the number of ephemeral ports available to any user. The valid range is
between 5000 and 65534 (decimal). The default value is 0x1388 (5000 decimal).
On the Edit menu, click Add Value, and then add the following registry value:
Value Name: TcpTimedWaitDelay
Data Type: REG_DWORD
Value: 30
This sets the number of seconds to hold a TCP port connection in TIME_WAIT state before
closing. The valid range is between 30 and 300 decimal, although you may wish to check
with Microsoft for the latest permitted values. The default value is 0x78 (120 decimal).
Quit Registry Editor.
Reboot the machine.
I will advise to use first check if my.ini exist in mysql folder in c drive or in windows folder
mysqld -install (Service successfully installed)
mysqld --initialize (no prompt)
Also another advise is not to use mysql 8, since it is not compatible with wordpress or any other opensource yet, there are lot of changes between version 5 and version 8, so if you are using mysql please use version 5.x.
Steps to resolve the problem ->
Go to command prompt and at root of c (c:\ if environment variable-path is set)
type -> c:\>mysqld -install.
Then type -> c:\mysqld --initialize
Now create one .txt file (here in our example we are taking init.txt) at root of mysql(may vary according to your directory) ->c:\MySQL\init.txt.
Now open that .txt file(init.txt) and write in it ->
5.open Run console and write -> Services.msc
6.Then Services window will be open ,there select MYSQL,Double click It and press start
7.Finally open new Command prompt window and type at root of c (c:) ->c:\>mysqlsh
due to this shell will execute and here you are ready to go....
mysql -u root --port 3308
this one help me
port number from phpmyadmin default port is 3306