Here are the steps I wrote for myself to follow, that I used to do my initial set-up.. (in case that was part of he problem some how?)
Used Etcher to flash latest Raspbian Stretch to micro SD card.
Added 'ssh' file to _root of SD card so I can connected via Putty/FTP..etc
Update Repositories:
-- sudo apt-get update
* Install Apache:
-- sudo apt install apache2 //new line
* Give permissions to Pi:
-- sudo chown -R pi:www-data /var/www/html/
-- sudo chmod -R 770 /var/www/html/
* Change Default Web Page:
-- ls -al
** I test if the server is working by opening the web browser and typing the Raspberry Pi's IP address.
** I find out the IP address by typing: ifconfig in the terminal (or my router)
* Install PHP:
-- sudo apt install php php-mbstring
Test PHP install:
//delete default apache index.html
-- sudo rm /var/www/html/index.html
//create new index.php file in its place, with the following content:
-- echo "" > /var/www/html/index.php
*** enabling PHP SHORT TAGS:
-- sudo nano /etc/php/7.0/apache2/php.ini //find short tags and edit/save config file (.ini)
* Install MySQL 7:
-- sudo apt install mysql-server php-mysql
** Type/Create root password when prompted //was never prompted to do so????
Check install:
-- sudo mysql --user=root
Add the wifi credentials:
Create file on the card called wpa_supplicant.conf, which has the following inside:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US
network={
ssid="Your network name/SSID"
psk="Your WPA/WPA2 security key"
key_mgmt=WPA-PSK
}
Edit country=, ssid= and psk= with your information and save the file.
Use the 2 letter country abbreviation in CAPS (without this you will have no WiFi).
Use a pure text editor, not a word processor, to edit the wpa_supplicant.conf file.
So all the above went fine..without much issue.. (followed an old wifi tutorial that disabled all DHCP ability..but thats been fixed now, and the steps updated above as well)
However.. there was ONE step I followed from this tutorials, how checking your MySQL install:
https://howtoraspberrypi.com/how-to-install-web-server-raspberry-pi-lamp/
"We will no delete the default mysql root user and create a new mysql root user, because the default one can only be used with Linux root account, and so not available for the webserver and php scripts.
To do so, once your connect to MySQL, simply run thoses commands (replace password with the password you want) :"
DROP USER 'root'#'localhost';
CREATE USER 'root'#'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost'
"So you now have a web server, connected to PHP and MySQL. That’s all it takes.
(On your next connections, you will be able to connect to mysql without using sudo, with the command:
"
# mysql --user=root --password=yourmysqlpassword
Now.. I can 'login' into PhpMyAdmin.. with the credentials above root/password...
but I have NO PRIVILEGES to create a database.. or add tables..etc
and when I'm logged into PhpMyAdmin.. I see these 'pink' alerts.. saying phpmyadmin#local host has no permissions/denied..etc..
So my question(s) are:
1.) What is the correct process after installing MySQL to set up a new user account? Are you supposed to be deleting the default account? Why didnt setting the new user account and privs work? (I get a denied, need an account with creation permissions...etc)
2.) How do I fix my current situation so I can continue with my project.. (which needs a database populated with data to display the site)
Do I need to un-install MySQL? and re-install it? Starting over? How will this affect everything else that is currently installed/working? Any backlash? Negative consequences here? I am new to Linux (Raspbian).. and CLI in general here..
Why didnt this line 'work'?
GRANT ALL PRIVILEGES ON . TO 'root'#'localhost'
And how can I fix this so I do have permissions to use PhpMyAdmin?
To update this, in cae anyone else stumbles upon it... it you look at the block...
its actually missing some syntax:
DROP USER 'root'#'localhost';
CREATE USER 'root'#'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost'
The last line is missing the ';' (semi-colon).. which means the last line did NOT execute.. (DOH!).. and hence.. new user has no privs!!!
I would suggest to not only FIX that typo... but also NOT drop the original ROOT user.. and just create a NEW account all together
ie:
CREATE USER 'admin'#'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'admin'#'localhost'
Related
After I went to phpMyAdmin to create new user.
Username: ken
Hostname: localhost
Password: 123456
Checked Global Privilege
When I start the MySQL console, it said that I need to enter the password. I pressed [ENTER] and it seem I have login to root. I haven't create password for root yet, Do I have to create a password for root? (I know it kinda dumb question, but I just want be crystal clear and simple answer)
Also, If I wanted to login to my newly created user, how do I do it?
I tried:
mysql> mysql -h localhost -u ken -p
->exit
Nothing happened.
The MySQL Console menu item in WAMPServer is setup to use the root account.
As the root account comes out of the box with no password set, then the correct thing to do is to just hit enter when the mysql processor asks for a password.
If you set a password on the MYSQL root account then when the MYSQL Console asks for a password you can use the newly created password.
If you want to login to MYSQL using a different user account, then it is simpler to use a command window and CD into the mysql folder and run the mysql.exe processor from there like
> cd \wamp\bin\mysql\mysql{version}\mysql
mysql -uken -p
I personally use a little batch file, that I store in a folder that is already on the windows PATH, never add a wamp folder to the windows PATH as this will mess you up when/if you ever install more than one version of MYSQL in your WAMPServer!
mysqlpath.bat
echo off
if %1.==. GOTO ERROR
PATH=%PATH%;c:\wamp\bin\mysql\mysql%1\bin
echo
echo -----------------------------------------------
mysql -V
echo -----------------------------------------------
echo
GOTO EndPHP
:ERROR
echo -----------------------------------------------
echo Parameter 1 should be something like 5.4.13 to use mysql5.4.13
echo -----------------------------------------------
:EndPHP
Then you run it like
>mysqlpath 5.7.10
and it sets that path up just for the duration of the command windows life.
First of all you have to logout of your current and then login with your new user:
For exiting just type:
> exit;
Then login with your new user:
$ mysql -u <username> -p
Keep in mind that:
By default mysql logic try with host localhost, otherwise if your server it's in another host just add the flag -h <your-hostname> at the end of your Shell request.
By default also, mysql try with port 3306, otherwise if your mysql's server port it's in another port just add --port=3333 at the end of your Shell request.
Keep in mind that if you aren't enable to run console interface of mysql you can use a Environment PATH for executing mysql otherwise you must edit your comand... changing mysql by the path to the wamp mysql bin location.
Let's supose you have mysql in this location: C:\wamp\bin\mysql\mysql5.7.19\bin, then, your comand will be:
D:\wamp2\bin\mysql\mysql5.7.19\bin\mysql.exe -u <username> -p
And that's it. If you have any issue please let me know, I will gladly help.
Resources:
How to manage MySQL databases and users from the command line
I have an issue trying to use SELECT INTO OUTFILE and using a directory other than /tmp.
My Linux user is named datam, my MySQL user is lea, and MySQL runs as mysql.
When datam runs mysql -u lea database and tries to do a SELECT INTO OUTFILE with a path of /home/datam/xfers/online/file.csv, I get an error code 13, permission denied. Using /tmp/file.csv works, so I'm fairly confident it is not an issue with permissions within MySQL.
I've added mysql to the datam group and have verified this with:
~$ sudo id mysql
uid=106(mysql) gid=114(mysql) groups=114(mysql),1001(datam)
I have /home/datam/ set as 775 recursively.
If I do sudo -u mysql /bin/bash and go to /home/datam/xfers/online/ and do touch file it writes a file.
What do I need to do to allow mysql to write a file from SELECT INTO OUTFILE?
I believe this is not a duplicate of other questions surrounding this subject, because I've looked at them and followed all of their instructions (setting execute on all directories leading up to the one I want, setting GRANT FILE ON, etc).
MySQL user lea grants:
+-----------------------------------------------------------------------------------------------------------+
| Grants for lea#localhost |
+-----------------------------------------------------------------------------------------------------------+
| GRANT FILE ON *.* TO 'lea'#'localhost' IDENTIFIED BY PASSWORD '*9BB439A3A652A9DAD3718215F77A7AA06108A267' |
| GRANT ALL PRIVILEGES ON `database`.* TO 'lea'#'localhost' |
+-----------------------------------------------------------------------------------------------------------+
This may be caused by mysql user permissions.
As stated here https://dba.stackexchange.com/questions/17029/cannot-output-mysql-data-to-file
To give yourself FILE privilege, do the following:
service mysql restart --skip-networking --skip-grant-tables
mysql <hit enter>
UPDATE mysql.user SET File_priv = 'Y' WHERE user='lea' AND host='localhost';
exit
service mysql restart
The linux user can write a file. But the mysql service may be blocked by apparmor.
Check this file: /etc/apparmor.d/usr.sbin.mysqld.
Add your project folder there:
/usr/sbin/mysqld {
[...]
/home/datam/xfers/online/ r,
/home/datam/xfers/online/* rw
[...]
}
Finally, do a
sudo /etc/init.d/apparmor reload
On modern systems mariaDB & mysql gets installed with systemd support. Among other things, it has this setting in /etc/systemd/system/mysql.service:
Prevent accessing /home, /root and /run/user
ProtectHome=true
That's what stops it from writing in /home.
I found that changing the owner of the directory to the same user as the mysql daemon worked for me.
I have sucessfuly reseted my root password on my localhost xampp. Now when I run the mysql daemon myself ( XAMPP/mysql/bin/mysqld.exe ), I can login with PHPMyAdmin to the MySQL administration with no problem.
However when I run MySQL from XAMPP's Control Panel (the "nice" window with start/stop etc. buttons)
I can't login through PHPMyAdmin anymore - I get error #1045...
This must be something configuration-related? What might be causing this?
Big thanks :)
It seems that mysql daemon in xampp has different default value for the basedir than the my.ini setting file.
So when I've reseted the password without adding the same --defaults-file as XAMPP does when it runs mysqld - I actually reseted a password for a different "workspace".
Thanks to #andy, because his comments led me to the solution :)
So the right way to reset XAMPP's MySQL root user ( on Windows ) is:
1) Stop MySQL with XAMPP Control
2) Prepare init file
Create file called mysql-init.txt directly on C:\ drive and fill it with this content:
#INSERT INTO mysql.user (User,Password) VALUES('root',PASSWORD('root'));
UPDATE mysql.user SET Password=PASSWORD('root') WHERE User='root';
GRANT ALL PRIVILEGES ON * . * TO 'root'#'localhost';
FLUSH PRIVILEGES;
- # is a comment - if you did not have a root user or deleted it by accident - uncomment the first line and comment the second line
These commands create a MySQL user "root" with password "root" and give him/her ALL privileges on everything.
3) Run MySQL daemon with proper params
Run YOUR_XAMPP_INSTALL\mysql\bin\mysqld.exe with these params:
Note the double slashes "\\" instead of single slashes "\"
--defaults-file="c:\\YOUR_XAMPP_INSTALL\\mysql\\bin\\my.ini"
--init-file=C:\\mysql-init.txt
So the whole command for cmd.exe could look like:
c:\YOUR_XAMPP_INSTALL\mysql\bin\mysqld.exe --defaults-file="c:\\YOUR_XAMPP_INSTALL\\mysql\\bin\\my.ini" --init-file=C:\\mysql-init.txt
Of course replace YOUR_XAMPP_INSTALL with the path to your custom xampp install ( very often it is just "xampp" resp. "C:\xampp"). And of course if you are operating on a different drive than "C", change C:\ to WhatEverLetterYouWant:\
4) Try to login on http://localhost/phpmyadmin/
Try to login on http://localhost/phpmyadmin/ with user root and password root, if it does not work, you have done something wrong in the previous 3 steps
5) 4) went fine? => Stop MySQL with XAMPP Control
6) Start MySQL with XAMPP control
7) Try to login again with root/root
8) 7) went fine? => Done :)
References:
http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html
https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-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".
I lost my MySQL username and password. How do I retrieve it?
Stop the MySQL process.
Start the MySQL process with the --skip-grant-tables option.
Start the MySQL console client with the -u root option.
List all the users;
SELECT * FROM mysql.user;
Reset password;
UPDATE mysql.user SET Password=PASSWORD('[password]') WHERE User='[username]';
But DO NOT FORGET to
Stop the MySQL process
Start the MySQL Process normally (i.e. without the --skip-grant-tables option)
when you are finished. Otherwise, your database's security could be compromised.
Unfortunately your user password is irretrievable. It has been hashed with a one way hash which if you don't know is irreversible. I recommend go with Xenph Yan above and just create an new one.
You can also use the following procedure from the manual for resetting the password for any MySQL root accounts on Windows:
Log on to your system as Administrator.
Stop the MySQL server if it is running. For a server that is running as a Windows service, go to
the Services manager:
Start Menu -> Control Panel -> Administrative Tools -> Services
Then find the MySQL service in the list, and stop it. If your server is
not running as a service, you may need to use the Task Manager to force it to stop.
Create a text file and place the following statements in it. Replace the password with the password that you want to use.
UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;
The UPDATE and FLUSH statements each must be written on a single line. The UPDATE statement resets the password for all existing root accounts, and the FLUSH statement tells the server to reload the grant tables into memory.
Save the file. For this example, the file will be named C:\mysql-init.txt.
Open a console window to get to the command prompt:
Start Menu -> Run -> cmd
Start the MySQL server with the special --init-file option:
C:\> C:\mysql\bin\mysqld-nt --init-file = C:\mysql-init.txt
If you installed MySQL to a location other than C:\mysql, adjust the command accordingly.
The server executes the contents of the file named by the --init-file option at startup, changing each root account password.
You can also add the --console option to the command if you want server output to appear in the console window rather than in a log file.
If you installed MySQL using the MySQL Installation Wizard, you may need to specify a --defaults-file option:
C:\> "C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt.exe" --defaults-file="C:\Program Files\MySQL\MySQL Server 5.0\my.ini" --init-file=C:\mysql-init.txt
The appropriate --defaults-file setting can be found using the Services Manager:
Start Menu -> Control Panel -> Administrative Tools -> Services
Find the MySQL service in the list, right-click on it, and choose the Properties option. The Path to executable field contains the --defaults-file setting.
After the server has started successfully, delete C:\mysql-init.txt.
Stop the MySQL server, then restart it in normal mode again. If you run the server as a service, start it from the Windows Services window. If you start the server manually, use whatever command you normally use.
You should now be able to connect to MySQL as root using the new password.
An improvement to the most useful answer here:
1] No need to restart the mysql server
2] Security concern for a MySQL server connected to a network
There is no need to restart the MySQL server.
use FLUSH PRIVILEGES; after the update mysql.user statement for password change.
The FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change.
The --skip-grant-options enables anyone to connect without a password and with all privileges. Because this is insecure, you might want to
use --skip-grant-tables in conjunction with --skip-networking to prevent remote clients from connecting.
from: reference: resetting-permissions-generic
Do it without down time
Run following command in the Terminal to connect to the DBMS (you need root access):
sudo mysql -u root -p;
run update password of the target user (for my example username is mousavi and it's password must be 123456):
UPDATE mysql.user SET authentication_string=PASSWORD('123456') WHERE user='mousavi';
at this point you need to do a flush to apply changes:
FLUSH PRIVILEGES;
Done! You did it without any stop or restart mysql service.
While you can't directly recover a MySQL password without bruteforcing, there might be another way - if you've used MySQL Workbench to connect to the database, and have saved the credentials to the "vault", you're golden.
On Windows, the credentials are stored in %APPDATA%\MySQL\Workbench\workbench_user_data.dat - encrypted with CryptProtectData (without any additional entropy). Decrypting is easy peasy:
std::vector<unsigned char> decrypt(BYTE *input, size_t length) {
DATA_BLOB inblob { length, input };
DATA_BLOB outblob;
if (!CryptUnprotectData(&inblob, NULL, NULL, NULL, NULL, CRYPTPROTECT_UI_FORBIDDEN, &outblob)) {
throw std::runtime_error("Couldn't decrypt");
}
std::vector<unsigned char> output(length);
memcpy(&output[0], outblob.pbData, outblob.cbData);
return output;
}
Or you can check out this DonationCoder thread for source + executable of a quick-and-dirty implementation.
If you have root access to the server where mysql is running you should stop the mysql server using this command
sudo service mysql stop
Now start mysql using this command
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
Now you can login to mysql using
sudo mysql
FLUSH PRIVILEGES;
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('MyNewPass');
Full instructions can be found here http://www.techmatterz.com/recover-mysql-root-password/
Login MySql from windows cmd using existing user:
mysql -u username -p
Enter password:****
Then run the following command:
mysql> SELECT * FROM mysql.user;
After that copy encrypted md5 password for corresponding user and there are several online password decrypted application available in web. Using this decrypt password and use this for login in next time.
or update user password using flowing command:
mysql> UPDATE mysql.user SET Password=PASSWORD('[password]') WHERE User='[username]';
Then login using the new password and user.
After MySQL 5.7.6 and MariaDB 10.1.20 (currently in 2022) you can:
Update a mysql user password having access to root user
ALTER USER 'some_user_name'#'localhost' IDENTIFIED BY 'a_super_secure_password';
Update mysql root user
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password by 'mynewpassword';
List all users
select user from mysql.user;
IF you happen to have ODBC set up, you can get the password from the ODBC config file. This is in /etc/odbc.ini for Linux and in the Software/ODBC folder in the registry in Windows (there are several - it may take some hunting)
Save the file. For this example, the file will be named C:\mysql-init.txt.
it asking administrative permisions for saving the file
Although a strict, logical, computer science'ish interpretation of the op's question would be to require both "How do I retrieve my MySQL username" and "password" - I thought It might be useful to someone to also address the OR interpretation. In other words ...
1) How do I retrieve my MySQL username?
OR
2) password
This latter condition seems to have been amply addressed already so I won't bother with it. The following is a solution for the case "How do i retreive my MySQL username" alone. HIH.
To find your mysql username run the following commands from the mysql shell ...
SELECT User FROM mysql.user;
it will print a table of all mysql users.