MySQL User Permission Errors using Sqitch on Ubtunu - mysql

I am running into what I think is a very easy issue to fix, I am just out of possible ideas.
I have a brand new Ubuntu 14.04 x64 server. I just installed MySQL. Not Apache, php or phpMyAdmin, just plain MySQL.
I have run through mysql_secure_installation and created a password for my root user.
I then put my root password in the /etc/mysql/my.cnf file under the [client] section.
I can run mysql -u root and get to the MySQL console just fine.
However, if I run sqitch deploy I get:
Access denied for user 'root'#'localhost' (using password: NO)
Sqitch is pointing to:
[target "database name_v1"]
uri = db:mysql://root#/databasename_v1
[engine "mysql"]
target = db:mysql://root#/databasename_v1
EDIT
It turns out the problem was with Sqitch and my configuration. Sqitch is a Perl application and needed the perl module MySQL Config in order to read the my.cnf file and access the database.

It turns out the problem was with Sqitch and my configuration. Sqitch is a Perl application and needed the perl module MySQL::Config in order to read the my.cnf file and access the database.

If you are using -v to get MySQL version, here's your answer : mysql -V
-v is for verbose output.
See this thread for more details.
"mysql -v" command line error(linux/ubuntu)

There are multiple root users in mysql. They are in the format user#remote.
You can check if the user password is set for all of those by running the query select Host, User, Password from mysql.user where User="root";
The output should show something like:
+--------------+----------+-------------------------------------------+
| Host | User | Password |
+--------------+----------+-------------------------------------------+
| localhost | root | *XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
| testvm | root | *XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
| 127.0.0.1 | root | *XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
If the password is empty, set it via mysqladmin.
From here on, your connection to mysql, whether coming from localhost, or coming from the hostname will be allowed to login.

Related

mysql fror mac, create databases ERROR 3680 (HY000) [duplicate]

I can't create a database after logging in mysql under my root account. Do I have to make an admin account to do so? Also, for some reason, my StartUp file didn't install (there was an error). I'm not sure if that will affect anything else since mySQL DOES start up when I type "mysql" into my terminal.
Also when I type in
mysql> SELECT Host, User FROM mysql.user;
+---------------------+------+
| Host | User |
+---------------------+------+
| 127.0.0.1 | root |
| ::1 | root |
| myname-mac.att.net | |
| myname-mac.att.net | root |
| localhost | |
| localhost | root |
+---------------------+------+
Which I don't get. I seem to have multiple root users and I don't know what ::1 means.
EDIT: My databases currently look like this.
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.02 sec)
And it doesn't matter what I type in as my database name. I even tried calling it 'apple'.
It might be problem with space.
Follow this
Check .err logs at /var/lib/mysql
if the log says something like
"[ERROR] Can't start server: can't create PID file: No space left on device"
Check /var size by df -hk /var
if used is 100% , then u have to find the files which is geting filled.
find large file in /var by
find /var/ -type f -size +100000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
see which file you can delete and then restart the mysql process by
/etc/init.d/mysql restart
let me know if that worked :)
If you're on macosx and if you've system preference pane installed, that should show a message like
the following directory is not owned by _mysql user - "/usr/local/msyql/data"
Once you know that path you can do the following:
sudo chown -R mysql:mysql /usr/local/mysql/data
sudo chown -R mysql:mysql <path>
You have one root user for several domains. Meaning you can connect and run queries on that database FROM the specified domains.
If you want to only show one, give it '%' for the domain and remove all others, although that is not advised. Save the root user for run rights only from localhost, and create limited users for running queries from outside.
As for test database error, it happens on fresh installs. Just reboot the mysql server(stop/start process) or the computer.
Also, make sure you have full rights by doing
GRANT ALL PRIVILEGES ON *.* TO 'root'#'thedomainyourunfrom/localhost/%' WITH GRANT OPTION;
this will give your root user full rights across all databases in the server
osx manual http://dev.mysql.com/doc/mysql-macosx-excerpt/5.0/en/macosx-installation.html
As an additional resource, you can try two other things:
Find out the data folder for your MySQL and 'chown' it so that mysql can write properly to it. For example, if your MySQL's data folder is /usr/local/mysql/data/, you can 'chown' it by typing up the command chown -R mysql:mysql /usr/local/mysql/data/
If you have just installed your MySQL server, try restarting your computer. Sometimes the installer fails on giving proper file access to the program
I hope that helps!

How to get mysql to use the current effective linux user as the default user in mysql?

If I login to a linux system as user alex, then change to user bob with su - bob, then as bob run mysql with no username arg specified, mysql will report (select user();) the user is alex.
I know I can do mysql -u bob to change the user, however I'm wondering if there's any way to configure mysql to use the current effective user (user reported by whoami) who ran the command mysql, bob in this example, to be used as the default when no username arg is specified to mysql? Thanks for any input.
Example:
Login as user alex
[alex#gc-instance-1 ~]$ mysql -e 'select user()'
+----------------+
| user() |
+----------------+
| alex#localhost |
+----------------+
[alex#gc-instance-1 ~]$ su - bob
Password:
[bob#gc-instance-1 ~]$ mysql -e 'select user()'
+----------------+
| user() |
+----------------+
| alex#localhost |
+----------------+
[bob#gc-instance-1 ~]$
Doesn't it work to create a .my.cnf file in the home directory of bob and put
[client]
user=bob
Alternatively you can also put password. Eg.
[client]
user=bob
password=1234
Then change the file permissions to read/write by owner (600)
Also explained at MySQL Manual
This way, you can just write 'mysql' and login without entering the password also.
PS. strangely in my system it uses the username of the whoever I became using 'su -' I am not sure why it is different in your machine. Manual says it defaults to unix username...

SELECT INTO OUTFILE permission denied but the user can write to the directory

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.

MYSQL no access/privileges how to change from a useless user to root?

The problem I have is when I get into the commandline for mysql I enter as ''#'localhost' and have no access to anything useful, I'm trying at the moment to get data back to a php page so I need a valid username and password. Is there a way I can create a user account with my feeble resources? Is there a way I can enter the MySQL commandline as root?
Any help appreciated.
If you user is root without any password (like a default MySQL setup), you should be able to connect using:
mysql --user=root
If you need to specify pwd as password:
mysql --user=root -ppwd
Check MySQL command line guide for other details.
When you install MySQL, it asks you to enter credentials for the root user.
If you had not done something like that, I recommend you to reinstall.
Moreover, I would recommend you to use a good package like PHPMyadmin to simplify your operations with databases.
http://www.phpmyadmin.net/home_page/news.php
You could also try Xampp, which has everything in a package - PHP, Tomcat, Mercury , Filezilla, PHPMyadmin and more if you'd like. You will spend almost 0 time configuring anything.
http://www.apachefriends.org/en/xampp.html
Previously, I was getting Access denied... errors for every command, but I was able to resolve the issue after reading RobbieE's suggestion and this documentation:
First, start mysql from the command line as the root user; this is the solution to your original question:
mysql -u root
Now if you'd like to password-protect root...
To see which accounts exist and check their passwords, execute:
SELECT User, Host, Password FROM mysql.user;
You should see an ASCII table, something like this:
+------+--------------------+----------+
| User | Host | Password |
+------+--------------------+----------+
| root | localhost | |
| root | 127.0.0.1 | |
| | localhost | |
+------+--------------------+----------+
Finally, set the password for each root user a la:
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('plaintext-password');
Re-execute statement 2 to verify the password was set correctly. You now have a useful and protected MySQL user for localhost. Do this again for 127.0.0.1 and any other hosts you may have.

mysql> create database test; ERROR 1006 (HY000): Can't create database 'test' (errno: 2)

I can't create a database after logging in mysql under my root account. Do I have to make an admin account to do so? Also, for some reason, my StartUp file didn't install (there was an error). I'm not sure if that will affect anything else since mySQL DOES start up when I type "mysql" into my terminal.
Also when I type in
mysql> SELECT Host, User FROM mysql.user;
+---------------------+------+
| Host | User |
+---------------------+------+
| 127.0.0.1 | root |
| ::1 | root |
| myname-mac.att.net | |
| myname-mac.att.net | root |
| localhost | |
| localhost | root |
+---------------------+------+
Which I don't get. I seem to have multiple root users and I don't know what ::1 means.
EDIT: My databases currently look like this.
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.02 sec)
And it doesn't matter what I type in as my database name. I even tried calling it 'apple'.
It might be problem with space.
Follow this
Check .err logs at /var/lib/mysql
if the log says something like
"[ERROR] Can't start server: can't create PID file: No space left on device"
Check /var size by df -hk /var
if used is 100% , then u have to find the files which is geting filled.
find large file in /var by
find /var/ -type f -size +100000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
see which file you can delete and then restart the mysql process by
/etc/init.d/mysql restart
let me know if that worked :)
If you're on macosx and if you've system preference pane installed, that should show a message like
the following directory is not owned by _mysql user - "/usr/local/msyql/data"
Once you know that path you can do the following:
sudo chown -R mysql:mysql /usr/local/mysql/data
sudo chown -R mysql:mysql <path>
You have one root user for several domains. Meaning you can connect and run queries on that database FROM the specified domains.
If you want to only show one, give it '%' for the domain and remove all others, although that is not advised. Save the root user for run rights only from localhost, and create limited users for running queries from outside.
As for test database error, it happens on fresh installs. Just reboot the mysql server(stop/start process) or the computer.
Also, make sure you have full rights by doing
GRANT ALL PRIVILEGES ON *.* TO 'root'#'thedomainyourunfrom/localhost/%' WITH GRANT OPTION;
this will give your root user full rights across all databases in the server
osx manual http://dev.mysql.com/doc/mysql-macosx-excerpt/5.0/en/macosx-installation.html
As an additional resource, you can try two other things:
Find out the data folder for your MySQL and 'chown' it so that mysql can write properly to it. For example, if your MySQL's data folder is /usr/local/mysql/data/, you can 'chown' it by typing up the command chown -R mysql:mysql /usr/local/mysql/data/
If you have just installed your MySQL server, try restarting your computer. Sometimes the installer fails on giving proper file access to the program
I hope that helps!