MySQL Workbench on Linux - mysql

I installed MySQL on Ubuntu 16.04. I can login to MySQL shell by typing the command:
sudo mysql -u root
However, I also want to see the DB via MySQL Workbench. I installed it on my computer, and when I go to Database -> Connect to Database I get the following window:
When I click 'OK' I get the following dialog:
I checked 1 and 2. 3 I don't know how to check and as for 4, I don't know what is the password at all (I don't have to use it to login via the console).
Do you know how to resolve it?

Firstly never work with root on a server. Period it is a bad habit. So first things first would be to log into the command line and create a user that is the root equivalent and then use that user.
So use the command line and then execute the following steps:
CREATE USER 'username'#'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'#'%'
WITH GRANT OPTION;
FLUSH PRIVILEGES;
This will create an administrative user called username. You can then use this account to log in. Get in the habit of doing this.

Use terminal login mysql
sudo mysql -u root
Initial root password
update user set password=PASSWORD(‘123456’) where User='root';
And then try workbench login again.
If you want to connect mysql service from any others host except localhost,
you need set root host to %
mysql -u root –p
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user; --check result,init value maybe 127.0.0.1 or localhost

I think that I found the problem. When I installed MySQL, I skipped the option to give a password to root user. Therefore, I decided to remove MySQL from my linux by using the command:
apt-get purge mysql mysql-server mysql-common mysql-client
and then re-install it by:
apt-get install mysql-server
This time, I gave a password to root user during the installation, and after the installation had been finished, I opened MySQL Workbench and used the password I gave during the installation.

Related

Mysql and phpmyadmin installation in RaspberryPi 3

I am trying to install mysql and phpmyadmin in my raspberrypi 3. I have followed many tutorials on the internet and specifically this link
https://www.youtube.com/watch?v=ozo_npQMQS8
now the problem is that while installing mysql i dont get any window in the command line asking for the password hence i am not able to set the root password..
I am able to get into mysql by "sudo"
sudo mysql -u root
but i am not able to login through the password.
the situation is same for the phpmyadmin. the installation is correct but i am not able to login with the password.
Thanks
So i figure out the problem is with the plugin. so i have to set the plugin to mysql_native_password.
To check the plugin type
USE mysql;
SELECT User, Host, plugin FROM mysql.user;
You may see that mysql_native_password is not there..
so to setup you may write these commands..
sudo mysql -u root
mysql> USE mysql;
mysql> UPDATE user SET
plugin='mysql_native_password' WHERE User='root'; mysql> FLUSH
PRIVILEGES; mysql> exit;
$ service mysql restart
So now you will be able to login both in phpmyadmin and in console through root password.
You shouldn't need 'sudo' because the -u in mysql -u root specifies the user account with which to connect (and the 'mysql' command should be available for all users, not just root; if not check your path). The reason you're not being prompted for a password is because you haven't told MySQL to use a password when connecting, to do that use -p like mysql -u root -p.
If you didn't set a password during installation, then there shouldn't be a password in which case mysql -u root should have worked for you. Once you've connected, you could set a password (which you probably ought to do for the two user accounts with username root and host '%' and 'localhost' (there may also be one for an IPv6 address). After setting the password, of course you'll need to use it when logging in with the -p flag.
If you're having trouble with phpMyAdmin, show us the error message and relevant part of your configuration file (config.inc.php).

MySQL: Not possible to login to DB without sudo (mysql-server-5.7)

I have installed mysql-server through sudo apt-get install mysql-server.
No when I want to login with mysql -u root -p I get the message ERROR 1698 (28000): Access denied for user 'root'#'localhost'.
But when I login with sudo mysql -u root -p it is possible, everything works fine.
What do I need to fix, that I can login to mysql without sudo command?
That's a permission issue, and working as intended : by default only the root linux user can execute the mysql daemon.
To allow it for other users, throw that command :
sudo chmod -R 755 /var/lib/mysql/
After that you have to restart the mysql daemon. Depending on your linux kernel, try one of these:
/etc/init.d/mysqld restart
or
service mysqld restart
Note that all this is NOT necessary and will lower the security. I see no reason why one would have to execute mysql with a normal user, except maybe on a shared server where several instances of mysql are running under the control of each user.
I was facing the same issue with mysql 5.7
Because normal user not having a priviledges to get the access
..
Open mysql :
sudo mysql -u root -P
Create new user and add all privileges to that user :
replace username and password according to your need. Replace avi and avi123
CREATE USER 'avi'#'localhost' IDENTIFIED BY 'avi123';
GRANT ALL PRIVILEGES ON *.* TO 'avi'#'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
As stated in this answer: https://askubuntu.com/questions/763336/cannot-enter-phpmyadmin-as-root-mysql-5-7/763359#763359
MySQL 5.7 changed the secure model, root login requires sudo now.
The solution is to create a new user and give them privileges.
The linked answer above solved my problem.
Only root user needs sudo for login . You can create a new user with all privileges and can be logged in without using sudo.
CREATE USER 'newuser'#'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON database_name.* TO 'newuser'#'localhost';
FLUSH PRIVILEGES;
Login:
mysql -u newuser -p

Using MySQL Workbench on Linux Mint 18

I've never had a MySQL install go smoothly. Not Mac. Not Windows. And now Linux joins the mess.
I installed mysql-server via Software Manager after a failed attempt with linuxbrew. I can actually run it in terminal, but I have to use sudo which seems odd. I don't see any examples where the user has to use sudo.
On top of that, when I run MySQL Workbench I can't connect. I get the error, Access denied for user 'root'#'localhost'
Any suggestions?
Did you install mysql from apt-get install mysql-server ? it probably asked you for a default root password (Ubuntu like systems usually do). If you have forgotten it, have no fear, the password can be reset
http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html#resetting-permissions-unix
Try doing this as linux root (sudo -i), if that doesn't work try
sudo -i
sudo mysql
and give it a shot.
Alternatively, sudo, connect to mysql and create another user account with full privileges something like
GRANT ALL ON *.* to someother user identified by ...
You cannot connect remotely with root database user since the default user created doesn't have access on '%' (remote access).
Create another user with limited rights (secure) and use it for workbench.
creating user on mysql:
create user test#'%' identified by 'test_user_password';
grant all on *.* to test; -- you can specify specific permissions/databases
flush privileges;
Try these credentials with workbench.
As far as the linux command line is concerned
mysql -uroot -p
-- hit enter, no password and see if you can get connected

Unable to access MySQL after it automatically generated a temporary password

I have erased and installed OSX 10.11 El Capitan and I have been following through this tutorial to get MySQL up and running on the new OS X. The first step was to download MySQL For Mac OS X 10.9 (x86, 64-bit), DMG Archive (works on 10.11, they recommended in the tutorial). While I were finishing installing the MySQL, I got the message saying that :
2015-10-25T02:10:54.549219Z 1 [Note] A temporary password is generated for root#localhost: R>gFySuiu23U
If you lose this password, please consult the section How to Reset the Root Password in the MySQL reference manual.
That was weird, I have never seen that kind of message. After that, I started MySQL via the Preference Pane and then use /usr/local/mysql/bin/mysql -v command on the terminal for another step. I got an error message saying that :
ERROR 1045 (28000): Access denied for user 'cheetah'#'localhost' (using password: NO)
I have also tried to access database through Sequel Pro using root as username and blank password, I got access denied message saying that :
Unable to connect to host 127.0.0.1 because access was denied.
Double-check your username and password and ensure that access from your current location is permitted.
MySQL said: Access denied for user 'root'#'localhost' (using password: NO)
Okay, I also tried this again using root as a username but 'R>gFySuiu23U' as a password (which was generated from MySQL). I got connection failed message saying that :
Unable to connect to host 127.0.0.1, or the request timed out.
Be sure that the address is correct and that you have the necessary privileges, or try increasing the connection timeout (currently 10 seconds).
MySQL said: Your password has expired. To log in you must change it using a client that supports expired passwords.
How could I solve this problem? I remember that MySQL has never got automatically generated a temporary password like this, hasn't it ?
Try this:
mysql -u root -h 127.0.0.1 -p
Enter password: (enter the random password here)
Ref:https://dev.mysql.com/doc/refman/5.7/en/data-directory-initialization-mysqld.html
Following this, you may reset your password using
ALTER USER 'root'#'localhost' IDENTIFIED BY 'new-password';
This is what worked for me on OS X Yosemite running MySql v5.7 (installed from the .dmg).
cd /usr/local/mysql/bin
./mysql -u root -p --connect-expired-password
(Enter the temporary password generated by the installer.)
This gets you into sandbox mode and mysql> prompt. Then set desired root password with SET PASSWORD:
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('mySuperSecretPassword');
Now that the password MySQL had generated is expired, the problem is reduced to getting this password to work again (1) or generate a new one (2). This can be accomplished by running MySQL with the skip-grant-tables option which would make it ignore the access rights:
Stop your MySQL server.
Add the below at the end of the [mysqld] section of my.cnf file and save it.
skip-grant-tables
Start MySQL server.
In terminal, type
mysql -u root -p
to get into MySQL command prompt.
In the command prompt, type
USE mysql;
to get into the mysql database where it keeps database users.
Type
UPDATE user SET password_expired = 'N' WHERE User = 'root';
to let MySQL know the password is not expired (1) or
UPDATE user SET authentication_string = PASSWORD('YourNewPassword'), password_expired = 'N' WHERE User = 'root';
to assign a new password YourNewPassword to root (2).
Doing these steps under OSX 10.11 El Capitan and MySQL 5.7.X, should do the trick.
Considering that you already have MySQL installed then..
Open a terminal window and type:
sudo /usr/local/mysql/support-files/mysql.server stop
sudo mysqld_safe --skip-grant-tables
Since the command fired in the step 2 will be under on going state, you need to open another terminal window and then type:
mysql -u root -p
UPDATE mysql.user SET password_expired='N', authentication_string=PASSWORD('') WHERE User='root';
quit;
sudo /usr/local/mysql/support-files/mysql.server restart
Important: in the step 2 you must replace for your password.
Hope it will wok for you.
MySQL password expired
Resetting the password will solve the problem temporarily, however, from MySQL 5.7.4 to 5.7.10 (I think to encourage better security) the default value for the default_password_lifetime variable is 360 (about a year). For those versions, if you make no changes to this variable (or to individual user accounts) all user passwords expire after 360 days.
Typically, from a script you might get the message: "Your password has expired. To log in you must change it using a client that supports expired passwords."
So, to prevent automatic password expiry, log in as root (mysql -u root -p), then, for clients that automatically connect to the server (e.g. scripts.) change the password expiration settings for those clients:
ALTER USER 'script'#'localhost' PASSWORD EXPIRE NEVER;
or you can disable automatic password expiration for all users:
SET GLOBAL default_password_lifetime = 0;
Links:
MySQL: Password Expiration and Sandbox Mode
MySQL: Password Expiration Policy
Password expiration policy in MySQL Server 5.7
I'm running macOS Sierra(10.12.3) and I installed mysql-5.7.17-macos10.12-x86_64.dmg.
The answer from #lesley worked for me with the exception that I needed to add ./ to ensure I was calling the mysql binary in my current working directory. Which is where the aforementioned package was installed.
If you cd to /usr/local/mysql/bin and run mysql -u root -p --connect-expired-password, you could receive the following error.
mysql: unknown option '--connect-expired-password'
I did. Because simply running mysql without providing a path, called a previously installed version of the MariaDB client.
So to ensure you are executing the correct binary, you can either
provide the absolute path
/usr/local/mysql/bin/mysql -u root -p --connect-expired-password
or the relative path after changing directories
cd /usr/local/mysql/bin
./mysql -u root -p --connect-expired-password
Both ways should work. Once you are connected to the client, the instruction are the same as above from #lesley.
Enter your temporary password generated by the installer and set your new password.
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('yourNewPassword');
I faced the same problem. I followed the installation process guide from https://www.ntu.edu.sg/home/ehchua/programming/sql/MySQL_HowTo.html and downloaded DMG archive and installed MySQL on my MAC OS X 10.12.2.
Finally executed the following commands on new Terminal.
cd /usr/local/mysql/bin
./mysql -u root -p --connect-expired-password
It worked.
Answer 7 worked for me: El capitan, MySQL installed from dmg and autogenerated password, but made sure to cd to /usr/local/bin/mysql before entering ./mysql -root -p Obvious, but I didn't the first time.
Now to find where all my databases and tables are and how to link them in.
For Mysql 5.7 I use
shell $ > sudo grep 'temporary password' /var/log/mysqld.log
This particular one did the trick for me:
As specified in this link: https://www.variphy.com/kb/mac-os-x-reset-mysql-root-password
Do all the steps except executing
UPDATE mysql.user SET Password=PASSWORD('NewPassword') WHERE User='root';
Execute
UPDATE mysql.user
SET authentication_string = PASSWORD('MyNewPass'), password_expired = 'N'
WHERE User = 'root' AND Host = 'localhost';
And then execute
FLUSH PRIVILEGES;
The another way to solve this issue is to use an older version of MySQL instead.
I have uninstalled MySQL version 5.7.9 for Mac OS X 10.9 (x86, 64-bit), DMG Archive and then install the older version, MySQL version 5.6.7 for Mac OS X 10.9 (x86, 64-bit), DMG Archive. This issue is solved. The given autogenerated password before finishing installation of this older version is gone and I can ultimately access the database using root as username and a blank password. Everything is working like a charm!
I installed view brew, and I had the same error message until I noticed this caveat:
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
To connect run:
mysql -uroot
To have launchd start mysql now and restart at login:
brew services start mysql
Or, if you don't want/need a background service you can just run:
mysql.server start
I got around this problem by running
'mysql -u root -p --connect-expired-password'
Then input the expired auto-gen password from mysql. Finally got in. Selected mysql db with
'use mysql'
and then updated user 'root' pw with
'ALTER USER 'root'#'localhost' IDENTIFIED BY 'your new password'
Installing MySQL manually by downloading packages for the first time generates a default password for root. Copy and save that. If not done somehow on successive re-installations it does not show that password.
Thus you cannot login to root.
Do the following :
Find mysql related entries from system
sudo find / -name mysql
Remove all mysql related entries by doing rm -rf <mysql_entries_above>
Download latest mysql-server and intall it.
You will be promted with a default password which you need to copy.
Run mysql_secure_installation and paste that password when asked for root.
Subsequently follow the steps and change admin password when prompted for.
Restarting Mysql server worked for me.
But in Mysql80-Server, it is more complicated than 5.7. In MySQL80 not allow you to update or change password during the config in my.cnf in state "skip grant table". So you need 3 big steps to do
I) change my.cnf to skip-grant-table
II) login MySQL with blank password & update table to blank password
III) restart mysql and login with blank password and update to new password
Step to do: (whatever, you forgot root password, temporary password gen by installation not work, etc. please follow the steps below) In my case on FreeBSD 12.2
stop your mysql server by
/usr/local/etc/rc.d/mysql-server stop
recheck again whether it is really stop (in case more serious problem than that)
/usr/local/etc/rc.d/mysql-server status
mysql is not running.
find your my.cnf file and add "skip-grant-tables" to it.
(normally before [Mysqldump] head)
restart mysql
/usr/local/etc/rc.d/mysql-server start
login to mysql
mysql -u root -p
when it ask for password, just press enter and you will log into mysql
select DB to use
use mysql
look at the table user
select user, authentication_string,password_expired from user;
update to blank password
UPDATE user SET authentication_string = '', password_expired='N' WHERE User = 'root';
quit mysql and make mysql stop
goto file my.cnf then take "skip-grant-tables" out of file.
restart mysql again with "mysql -u root -p" enter the blank password
then
ALTER USER 'root'#'localhost' IDENTIFIED WITH
caching_sha2_password BY 'YourNewPassword';
quit mysql and make mysql stop
restart mysql again then you will login with your new password
This may happens when you have installed mysql before.
Try the password you set for the last version of mysql.
This did work for me.

Access denied for root user in MySQL command-line

I've just installed xampp, and am using command line to write mySQL.
I am using 'root' with no password and can connect to mysql but cannot CREATE DATABASE as I get the error 1044 access denied for user '' # 'localhost'. I am logged in as -uroot.
I have privileges in phpMyadmin to do what I want, but, in command line I seem to have no write privileges. I've looked at all the other related posts on this topic but to no avail. I cannot GRANT privileges as I have none anyway.
Are you logging into MySQL as root? You have to explicitly grant privileges to your "regular" MySQL user account while logged in as MySQL root.
First set up a root account for your MySQL database.
In the terminal type:
mysqladmin -u root password 'password'
To log into MySQL, use this:
mysql -u root -p
To set the privileges manually start the server with the skip-grant-tables option, open mysql client and manually update the mysql.user table and/or the mysql.db tables. This can be a tedious task though so if what you need is an account with all privs I would do the following.
Start the server with the skip-grant-tables option
Start mysql client (without a username/password)
Issue the command
flush privileges;
which forces the grant tables to be loaded.
Create a new account with the GRANT command something like this (but replacing username and password with whatever you want to use.
GRANT ALL on *.* to 'username'#'localhost' identified by 'password';
Restart the server in normal mode (without skip-grant-tables) and log in with your newly created account.
Refer this MySQL docs.
navigate do C:\xampp\mysql\bin\ and make sure the file mysql.exe is in that folder.
mysql -uroot -p
if dont have a password just press enter.
the prompt changes to
mysql>
do your mysql commands
By default there is no password is set for root user in XAMPP.
You can set password for root user of MySQL.
Navigate to
localhost:80/security/index.php
and set password for root user.
Note:Please change the port number in above url if your Apache in on different port.
Open XAMPP control panel Click "Shell" button
Command prompt window will open now in that window type
mysql -u root -p;
It will ask for password type the password which you have set for root user.
There you go ur logged in as root user :D Now do what u want to do :P
Gain access to a MariaDB 10 database server
After stopping the database server, the next step is to gain access to the server through a backdoor by starting the database server and skipping networking and permission tables. This can be done by running the commands below.
sudo mysqld_safe --skip-grant-tables --skip-networking &
Reset MariaDB root Password
Now that the database server is started in safe mode, run the commands below to logon as root without password prompt. To do that, run the commands below
sudo mysql -u root
Then run the commands below to use the mysql database.
use mysql;
Finally, run the commands below to reset the root password.
update user set password=PASSWORD("new_password_here") where User='root';
Replace new_password _here with the new password you want to create for the root account, then press Enter.
After that, run the commands below to update the permissions and save your changes to disk.
flush privileges;
Exit (CTRL + D) and you’re done.
Next start MariaDB normally and test the new password you just created.
sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
Logon to the database by running the commands below.
sudo mysql -u root -p
source: https://websiteforstudents.com/reset-mariadb-root-password-ubuntu-17-04-17-10/
I had the same issue, and it turned out to be that MariaDB was set to allow only root to log in locally via the unix_socket plug-in, so clearing that setting allowed successfully logging in with the user specified on the command line, provided a correct password is entered, of course.
See this answer on Ask Ubuntu
I re-installed the ODBC connector msi and re-installed mySQL directly (aside from xampp) and it now works. It was a connector problem I think, as SHOW DATABASES wasn't actually showing my databases at all.
My 'root' login wasn't getting access to the DB, which made it seem like it had limited priviliges but it actually wasn't connected properly.
Server file only change name folder
etc/mysql
rename
mysql-
this might help on Ubuntu:
go to /etc/mysql/my.cnf and comment this line:
bind-address = 127.0.0.1
Hope this helps someone, I've been searching for this a while too
Cheers
You mustn't have a space character between -u and the username:
mysql -uroot -p
# or
mysql --user=root --password