I'm new to setting up my own database server and linux server, but I'm working on a project that needs to use phpCake and mysql. I have a turnkey linux install of LAMP, with phpCake installed on it. My Cake install is fine, however I can not get into mysql.
mysql command yields error 1045, access denied for user root#localhost using password: no
mysql -u root -p
'rootpasswordhere'
yeilds the same thing, except using password:yes
I've read many fixes involving stoping mysql and setting a new password. I've had none of those work for me. The mysql stop command is denied in the same way the mysql command is. When I use service stop mysql my input cursor gets strange and no longer captures any input.
I'd love any help or input. I'll try out any of the fixes out there again and detail what happens. I'm sorry if this has been answered before, but trying the fixes I've found over the last few hours don't seem to work. Unsure if it is me, or my actual problem.
Thanks!
Depending on which linux you are running:
Stop service:
sudo service mysqld stop
Run these commands to write a temporary SQL file (/tmp/my.sql):
sudo echo "UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';" > /tmp/my.sql
sudo echo "FLUSH PRIVILEGES;" >> /tmp/my.sql
Start the service with script:
sudo /usr/bin/mysqld_safe --init-file=/tmp/my.sql &
---------------------------------------------------------------------------------^ The ampersand runs the process in the background allowing you to continue using the terminal.
Now you should be able to connect with your new root password MyNewPass
Note: Be sure to a) change the root password and b) remove /tmp/my.sql once completed.
Related
I have downloaded and installed the appropriate version for my 2014 macbook and my server is running. I have done the bash code thing that I don't understand but the next step is
Mysql -u root -p
Enter password:
Now I have tried everything to do this. I know the mac terminal does not show the password as you type. That's not the problem I have also tried using
Mysql -u root -password ='temppassword'
But this time it tells me it's not safe to write passwords in the line and rejects me
The temporary password that the program gave me includes "+ and &" symbols. Is that the problem? How can I solve this? I can't even start my mysql Journey.
I am trying to get MySQL running on my localhost. This never happened to me before, but upon installation sudo apt-get install mysql-server did not ask me for the initial password.
After searching for answers to "reset" my password and battling with directory permissions, i am currently at this state:
The mysqld_safe solution:
After rebooting my computer, mysql -u root -p will ask me for my password, and after i enter it, it will complain with ERROR 1698 (28000): Access denied for user 'root'#'localhost'
If i instead try mysql -u root (no password), it will say ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
If i run the advice that other people have posted about resetting the password via mysqld_safe --skip-grant-tables, then i run across some hiccups along the way:
First i run sudo service mysql stop
Then sudo mysql_safe --skip-grant-tables will say mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.
I can fix that if i do sudo mkdir -p /var/run/mysqld and sudo chown mysql /var/run/mysqld
After this, running mysqld_safe will run with the message Starting mysqld daemon with databases from /var/lib/mysql and then hang. And Ctrl+C doesn't get me out of that.
In a new terminal window i can now actually connect with mysql -u root and get the mysql> prompt.
I can set a new password with use mysql; update user set authentication_string=password('0000') where user='root';flush privileges; which will tell me it successfully updated the row with the message Rows matched: 1 Changed: 1 Warnings: 1
The warning only states: 'PASSWORD' is deprecated and will be removed in a future release.
And after all this, i'm back at square one: The process still hangs, so i have to reboot because killall mysqld_safe says no process found. After rebooting and entering my new password 0000, i will get access denied.
The system is Linux 4.15.0-48-generic #51-Ubuntu SMP.
The mysqladmin solution
If i run mysqladmin -u root password '0000' (without sudo), i get:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'#'localhost''
If i run it with sudo, i get:
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
This last one doesn't really tell me anything in regards of whether the password change happened or not; has it been refused or not (since it's a warning, not an error, i would assume it should go through), but in either case, trying to connect with 0000 still says "access denied".
Any advice on how to fix this is greatly appreciated.
I didn't quite solve the problems with mysql directly; However for myself, the acceptable solution was switching to a different database software, but it's still a MySQL system, and it got me up and running. So if anyone gets stuck on existing solutions not working like i did, maybe this comes in handy to get you on the road and finally writing code again.
What i did was:
Purged mysql off my system
Manually deleted /etc/mysql and /var/lib/mysql (don't know if this step was necessary)
apt clean, apt autoremove, apt update
Installed mariadb
Followed these instructions to rid myself of the timeout bug
Used the mysqld_safe --skip-grant-tables method to create a new user with all privileges, since connecting with root always kept failing
PHP + MariaDB now working again.
(After two hours of researching how to use mysql commands in the terminal, I can finally post this question, BTW if anyone with macOS is having the same trouble that can't use mysql commands in the terminal, go straight to this straight to this link: solution.)
I have a Mac os Sierra, I'm completely new to MySQL. I first downloaded the workbench and the MySql server, it gave me a temp password, I created a local connection, it worked. Then, I deleted the old connection, and created another connection, it asks for the password, and it wouldn't work, so right now I'm trying to reset and change my mysql password, but I've been having a lot of trouble with it.
Since the SQL office website only has instructions for windows and unix, and I'm rather new to bash, I tried to find solutions somewhere else like this site.
1. Attempt
When I tried the solution from this link site1, as I try the first step, it asks for a password which I don't have, I tried the old password just to try and it didn't work.
YupengdeMacBook-Pro:~ yinyupeng$ sudo /usr/local/mysql/support-files/mysql.server stop
Password:
Then, I realized that I can close my server directly in the MacOS setting, I did that, and I jumped to the second step directly, it still asks for a password:
YupengdeMacBook-Pro:~ yinyupeng$ sudo mysqld_safe --skip-grant-tables
Password:
So I'm stuck here, can't go further with this solution.
2. Attempt
then I tried this site2, but as I type the first line, it tells me this:
YupengdeMacBook-Pro:~ yinyupeng$ mysql -u root
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
Umm... ok, so then I tried to find solutions for that "access denied" error, but with little results.
So I'm not sure what to do now, please help, thank you very much.
BTW, my SQL version is:
YupengdeMacBook-Pro:~ yinyupeng$ mysql --version
mysql Ver 14.14 Distrib 5.7.19, for macos10.12 (x86_64) using EditLine wrapper
YupengdeMacBook-Pro:~ yinyupeng$
You can try reseting the root password by running MySQL in Safe Mode.
Here are the steps:
Stop MySQL:
sudo /usr/local/mysql/support-files/mysql.server stop
Start it in safe mode:
sudo mysqld_safe --skip-grant-tables
This will be an ongoing command until the process is finished so open another shell/terminal window, and..
Log in without a password as root:
mysql -u root
Update root (and any other user's) password)
FLUSH PRIVILEGES;
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';
\q
Restart MySQL in normal mode
sudo /usr/local/mysql/support-files/mysql.server start
Reference: https://coolestguidesontheplanet.com/how-to-change-the-mysql-root-password/
Note: this is pretty much a copy-paste from the reference link. this is pretty standard reset procedure, but just documented better in that guide compared to mysql reference docs.
You can edit your mysql configuration file and add skip-grant-tables to the section [mysqld]
or
Start mysqld and send it to background
mysqld_safe --skip-grant-tables &
I downloaded MySQL 5.7.17 for Mac and installed it. I can start and stop the SQL server from my Preferences > MySQL. It is shown as an instance on port 3306 from Workbench so all that seems fine. However, during install toward the end a pop-up window listed a password I was supposed to use. I assumed it would be promptly needed so copied on the clipboard. Few mins later having not been prompted for it yet, I copied something else in the clipboard thus losing it.
I have been trying to get some sort of client of mysql command line so I can enter sql commands, however there is no "Application" installed to use to access the server. I have scoured the MySQL documentation and Stack and beyond, and searched for how to get the password reset, and a mysql client/command line, but all the articles seem to assume you already have access to a "MySQL terminal"/"command line". I only have access to my normal Mac Terminal, and most commands in the normal Terminal window either fail or require the password I don't have, for example:
$ mysqld --skip-grant-tables
-bash: mysqld: command not found
$ mysql -u root -p
-bash: mysql: command not found
$ sudo sh -c 'echo /usr/local/mysql/bin > /etc/paths.d/mysql'
Password: (this is probably the password I was given that got overwritten? When I try the admin password of the machine it sends me back to the prompt)
$ sudo mysqld_safe --skip-grant-tables (after I'd stopped the server)
sudo: mysqld_safe: command not found
Can somebody please help me figure out how to get to a "MySql Terminal" and if I need this password that got overwritten, how to reset it? (it seems like uninstalling MySQL to repeat the steps and this time take better care of the password is actually horrendously difficult / no uninstall protocol?).
Thank you so very much.
--- Update: I used the How To Uninstall suggested by Josh M and then re-installed. This time I saved the password (so far, not sure how / where I need to use it). However, I must really be missing something b/c I still can't get access to mysql.
/usr/local/mysql/bin/mysql
ERROR 1045 (28000): Access denied for user 'Robert'#'localhost' (using password: NO)
Then I did $ export PATH=$PATH:/usr/local/mysql/bin but I still get ERROR 1045.
Try these set of commands
$ sudo /usr/local/mysql/support-files/mysql.server stop
$ sudo /usr/local/mysql/support-files/mysql.server start --skip-grant-tables
/usr/local/mysql/bin/mysql
FLUSH PRIVILEGES;
ALTER USER 'root'#'localhost' IDENTIFIED BY 'YOUR_NEW_PASSWORD';
EXIT;
$ sudo /usr/local/mysql/support-files/mysql.server stop
$ sudo /usr/local/mysql/support-files/mysql.server start
$ mysql -u root -p
$ Enter Password: 👉🏻 ENTER_YOUR_NEW_PASSWORD_HERE 👈🏻
And enjoy 🎉
There's a tutorial for resetting passwords here: https://www.howtoforge.com/setting-changing-resetting-mysql-root-passwords
Your MySQL command line interface (cli) is probably at:
/usr/local/mysql/bin/mysql
Honestly it might be better to reinstall. There's an SO on that: How do you uninstall MySQL from Mac OS X?
Fedora release 23 (Twenty Three) - I installed phpMyAdmin, I navigate to it (http://127.0.0.1/phpmyadmin/index.php, or using http://localhost...). id=root, and my password does not work, just get the message Cannot log in to the MySQL server.
Yet, I can log into MySql using, sudo mysql -u root -p and entering my password. From mysql I even tried changing my password (to the same thing) using:
UPDATE mysql.user SET Password=PASSWORD("mypasswordhere") WHERE User="root"; and, FLUSH PRIVILEGES;
but still cannot log into phpmyadmin.
Again, can log into MySql via command line, but cannot log into phpMyAdmin. trying port 8889 does not work, either. Only 80 default gets me to the login page. Help?
Important part from the question on Serverfault:
Make sure you have allowed SELinux boolean:
# setsebool -P httpd_can_network_connect_db on
It should probably help investigating SELinux messages in audit (ausearch -m AVC) or temporarily switch SELinux to Permissive mode (setenforce 0) to make sure it is the real cause.