mysqldump is not saving user password - mysql

I am using mysqldump to save my database and now want to reconstruct it completely, including the database, the users, and the user permissions.
mysqldump --databases my_db mysql -u root -p > mysqldump.sql
This generates the sql to create the database and it creates the user in the following table:
INSERT INTO db VALUES ('localhost','my_db','my_user','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
However, the password for the user does not appear anywhere in the file and it's not clear to me how I can use the user to access the DB once I have recreated the DB.
I cannot use the --all-databases option because there is another DB with tons of data and I do not want that in the file.

You are looking at the incorrect table in your dump:
Look at the table:
CREATE TABLE `user` (
`Host` char(60) COLLATE utf8_bin NOT NULL DEFAULT '',
`User` char(80) COLLATE utf8_bin NOT NULL DEFAULT '',
`Password` char(41) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL Etc
The INSERT statement after that contains your passwords

The user name and password are not part of the database, but are part of the special mysql database. If you want to replicate the user accounts, take a dump of the mysql database and restore it on the other end and then use flush privileges command to refresh the user table in the DB.

Whenever you assign privilege to any user then entry goes as per below-
If you are assigning privileges on all dbs like . then entry will go only in user table.
If you are assigning privileges db wise like mydb.* then one entry will go in user table which contains all privilegs with 'N' permission & keep user password there and 2nd entry in db table which contains appropriate rights.
mysql db contains user privileges as per below-
global rights (all db) with user anme and password : user table
db wise rights in : db table
table wise rights in : tables_priv table
column wise rights in : columns_priv table.
So you are checking db table, which contains db wise rights but not password as password is stored only in user table.

Related

MySQL query fails to run, but no error displayed

When i enter this SQL snippet into phpMyadmin nothing happens, and no error message is returned.
What can I do to fix it?
CREATE DATABASE `moodle`
DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER ‘moodle-owner’#’localhost’;
CREATE USER ‘moodle-owner’#’127.0.0.1’;
CREATE USER ‘moodle-owner’#’::1′;
SET PASSWORD FOR ‘moodle-owner’#’localhost’ = PASSWORD(‘moodle123$%’);
SET PASSWORD FOR ‘moodle-owner’#’127.0.0.1’ = PASSWORD(‘moodle123$%’);
SET PASSWORD FOR ‘moodle-owner’#’::1′ = PASSWORD(‘moodle123$%’);
I'm not sure what version of MySQL you are running, but in 5.7, the SET PASSWORD is deprecated. Try setting the user passwords with IDENTIFIED BY in the same query as CREATE USER.
CREATE USER 'moodle-owner'#'localhost' IDENTIFIED BY 'moodle123%';
CREATE USER 'moodle-owner'#'127.0.0.1' IDENTIFIED BY 'moodle123%';
CREATE USER 'moodle-owner'#'::1' IDENTIFIED BY 'moodle123%';

MySQL - Login fails with incorrect match of case for username

I am unable to login to mysql unless I provide exact case match for a user I have in my database.
After looking into the issue I believe my problem is with the collation but I am not sure. I tried to alter collation for the mysql.user table, User column to be latin1_swedish_ci but still could not get it to recognize alternate cases for usernames when I try to login.
My new username is admin ( all lowercase)
The command I am running is
mysql -u admiN -p <------ with username ending in a capital letter
Prior to running the command I ran the SQL statement below.
Here is the command I ran with apparently no effect (Original Collation was utf8_bin)
ALTER TABLE `user` CHANGE `User` `User` CHAR(16) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT '';
Each time I get the following response.
ERROR 1045 (28000): Access denied for user 'admiN'#'localhost' (using
password: YES)
Only when I login with all lowercase for the username do I succeed in entering into mysql.
Am I missing something else here to get it working? How do I change the mysql configuration to accept case insensitive usernames?

Creating tables failed

I have installed mySQL Server and created a user called ej_instance and has set password "password". Logged into server using below command
mysql -u ej_instance -p;
-- entered password
ej_instance has access to only ejabberd database. So I executed command like below
use ejabberd;
Then tried to execute commands like below
SET table_type=InnoDB;
CREATE TABLE users (
username varchar(250) PRIMARY KEY,
password text NOT NULL,
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) CHARACTER SET utf8;
But it is throwing errors at me. Below are errors
ERROR 1193 (HY000): Unknown system variable 'table_type'
ERROR 1046 (3D000): No database selected
How can get this done? anything else to be changed?
Specify the engine type when creating the table, like this:
USE ejabberd;
CREATE TABLE users (
username varchar(250) PRIMARY KEY,
password text NOT NULL,
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) CHARACTER SET utf8 ENGINE = INNODB;
If the use error still showing, check:
the database exists
the user ej_instance has privileges to access and create tables on the database
Loggin as root:
#check the database exists
SHOW DATABASES LIKE 'ejabberd';
#check user permissions
SHOW GRANTS FOR 'ej_instance'#'localhost';
SHOW GRANTS FOR 'ej_instance'#'%';
If don't have enough permissions:
#grant all permission on the user for the specified database
GRANT ALL ON ejabberd.* TO 'ej_instance'#'localhost';
GRANT ALL ON ejabberd.* TO 'ej_instance'#'%';
FLUSH PRIVILEGES;

PHP myadmin import database failure

I am trying to import my old database back into phpmyadmin after deleting it and creating a new one...steps taken....deleted database after back up....created new database with different name and received this error when trying to import
1044 - Access denied for user 'augr_2'#'%' to database 'augr_2'
After some research i found that i must change my CREATE DATABASE line in my database .sql file after amendment it looked like this
CREATE DATABASE `augr_2` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `augr_2`;
But i still keep getting this error?
this is the full error i receive
SQL query:
--
-- Database: `augr_2`
--
CREATE DATABASE `augr_2` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
MySQL said:
1044 - Access denied for user 'augr_2'#'%' to database 'augr_2'
It looks like the mysql used by the PMA doesn't have rights on the newly created db , which is normal.
Try this logged it as root
GRANT ALL ON *.* TO 'augr_2'#'%';
FLUSH PRIVILEGES;

How to get started with PostgreSQL similar to MySQL

I am not getting a clue to:
simply login to postgreSQL
Create a database
Add a table
Insert a record
Delete , update etc
These things are normally very very easy using mysql . Can someone help me setup following alternative for postgresql
a) Reset default password -- Very Clean description ,
I do not find same level of clarity for PostgreSQL
(Any documentation link is highly appreciated)
b) We know the superuser for mysql is "root" what is the same for PostgreSQL
c) from command line how to ( PostgreSQL ones ?):
mysql -uroot -proot
create database testdb;
use testdb;
create table test(id int(11) auto_increment, name varchar(20), primary key(id));
insert into test(name) values("testing one"),("testing two"),("testing three"),("testing four");
select * from test;
update test set name=concat(name,now()) where id =3;
delete from test where id =4;
drop table if exists test;
drop database if exists testdb;
EDIT MAC OS
# Default password reset
sudo mate /Library/PostgreSQL/9.2/data/pg_hba.conf
replaced (md5 with trust)
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
with
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
save
executed the Reload Configuration.app
login to postgresql without password :
$ psql -U postgres
postgres# ALTER USER postgres WITH PASSWORD 'new password';
\q
-revert back all the changes in pg_hba.conf (replace trust with md5) and save
-reload configuration
Now I can login to postgresql with new password
psql -U postgres
Password for user postgres:[my new password]
To login:
psql -d postgres_dbname -U postgres
Create Database:
create database testuser;
\c testuser; /*use testuse as mysql*/
Create Table:
create table employee (Name char(20));
Insert :
insert into employee VALUES ('XAS');
Update Link
Delete Link
Reset Password : See Here &
See Here Too
Simply login to postgreSQL
psql -U postgres -W template1
-U = username
postgres is root
-W = ask for password
tempalte1 = default database
Create a database
-- Create the database from within postgresql
create database my_database_name
-- Connect to the database
\c my_database_name
-- Create the database without logging in
createdb -U postgres -W my_database_name
Add a table
Insert a record
Delete , update etc
All the above from 3 to 5 are like in MySQL
For resetting postgres forgotten password this link is a good reference.
postgresql is a completely different system than mysql; so do not assume things will be like mysql. They are completely different animals entirely; some of your SQL statements might not work, especially if you are using a MySQL proprietary command.
To login to postgresql, use the psql command shell
CREATE DATABASE
CREATE TABLE
INSERT
For all other basic SQL commands, consider going through the tutorial
User access control is something more fine grained and detailed in postgresql. There are users and roles. A user is simply a role that has the ability to login (like MySQL), but in postgresql you can have roles (an account) that cannot login.
What access a role has is defined in pg_hba.conf. This file defines if a role can login at all, by what means are they authenticated, from where they can login and what database they have access to.
ALTER USER is used to reset credentials.
The "root user" for postgresql is typically postgres; and this is a system user that is created during the install process. For Windows, the binary installer will ask if you want to launch the service as this user as well.
Please take a look at this PostgreSQL error 'Could not connect to server: No such file or directory'
Try to install postgresApp, this solved my problem which was the same of yours.