I am trying to fix the problem with MySQL Server. When I type in terminal MySQL I get command not found.
I know I have to edit .bash_profile file and add to it this line:
export PATH=${PATH}:/usr/local/mysql/bin
The problem is I can't write to it. I tried these commands:
brackets ~/.bask_profile
sudo brackets ~/.bash_profile
touch ~/.bash_profile; open ~/.bash_profile
sudo touch ~/.bash_profile; open ~/.bash_profile
All the time I get a message that I am not allowed to write to this file because it is protected.
My question is, how can I write to this file and start MySQL Server?
Thank you for your help.
Cheers
EDIT:
Output in terminal of command:
ls -l ~/.bash_profile
is
-rw-r--r-- 1 root staff 447 13 paź 17:33 /Users/macos/.bash_profile
EDIT2:
Could you write to me about how to find the path to the .bash_profile file? I think changing the privileges of this file will be the solution to the problem.
The solution was using vi/vim editor:
vi ~/.bash_profile
Then in vi/vim I pasted this line:
export PATH=${PATH}:/usr/local/mysql/bin
And saved it with this commands:
:wq!
I'm attempting to edit my my.cnf file to allow remote access to mysql (by changing the bind-address). However, I'm getting a "Error writing my.cnf: Permission denied" error when I try to save (using pico through SSH).
Running $ lsattr my.cnf returns ---------------- my.cnf
What do I need to do to be able to edit this file?
Thanks!
You need to set the file permission as readable and writable.
sudo chmod 644 my.cnf
sudo nano my.cnf
sudo chmod 644 my.cnf
sudo pico my.cnf
Try to edit it as root.
Or look for at the file owner and file right with an ls -a.
when I use mysqlbinlog command I can't find the file.
lihaodeMacBook-Pro:data lihao$ mysqlbinlog --start-position=106 --stop-position=125 mysqlbin.000001 > ~/tmp1.sql
mysqlbinlog: File 'mysql-bin.000001' not found (Errcode: 13)
lihaodeMacBook-Pro:data lihao$ ls -a
. ib_logfile0 library mysql-bin.000001
.. ib_logfile1 lihaodeMacBook-Pro.local.err mysql-bin.000002
lihaodeMacBook-Pro:data lihao$ mysqlbinlog /usr/local/mysql-5.1.63-osx10.6-x86_64/data/mysql-bin.000001
/*!40019 SET ##session.max_insert_delayed_threads=0*/;
/*!50003 SET #OLD_COMPLETION_TYPE=##COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
mysqlbinlog: File '/usr/local/mysql-5.1.63-osx10.6-x86_64/data/mysql-bin.000001' not found (Errcode: 13)
I find the solution of the question by myself.I can't find the file because I don't have permission to read or write the file.I can use the command by add sudo at front of the commend.
Mysql Server 5.7 issue resolved:
there are two possibilities over here.
One is either your bin-log file is in /var/log/mysql in that case:
cd /var/log/mysql/
then access the file as sudo user
sudo mysqlbinlog mysql-bin.00000x
if file is in /var/lib/mysql then one needs sudo access to even read the file so follow these two steps:
Login as sudo root user
sudo -i
Once u are sudo user then go to the following directory: (without being a sudo user this location will deny the permission to even enter the directory)
cd /var/lib/mysql/
after that access the file
sudo mysqlbinlog mysql-bin.00000x
In my case it was permission related. Ensure you're sudo when using mysqlbinglong utility.
Should somebody submit an issue to the creators of the mysqlbinlog utility ? The error should be a bit more clear in my opinion.
I have installed MySQL 5.6.17 on my Ubuntu 14.04 following the instructions at http://dev.mysql.com/doc/refman/5.0/en/binary-installation.html.
The instructions says to use the optional command :
shell> cp support-files/my-medium.cnf /etc/my.cnf
But I do not see any "my-medium.cnf" file in the folder.
The instructions also mentions :
shell> cp support-files/mysql.server /etc/init.d/mysql.server
What exactly is the purpose of copying this file to the destination?
You can replace my-medium.cnf with my.cnf ,Because you use data directory and base directory at some where.MySQL need a path to access those directories.So inorder to make this changes you have to work with .cnf files.So it is understandable that you can make a copy of it.Before you edit.
I am trying to dump the contents of a table to a csv file using a MySQL SELECT INTO OUTFILE statement. If I do:
SELECT column1, column2
INTO OUTFILE 'outfile.csv'
FIELDS TERMINATED BY ','
FROM table_name;
outfile.csv will be created on the server in the same directory this database's files are stored in.
However, when I change my query to:
SELECT column1, column2
INTO OUTFILE '/data/outfile.csv'
FIELDS TERMINATED BY ','
FROM table_name;
I get:
ERROR 1 (HY000): Can't create/write to file '/data/outfile.csv' (Errcode: 13)
Errcode 13 is a permissions error, but I get it even if I change ownership of /data to mysql:mysql and give it 777 permissions. MySQL is running as user "mysql".
Strangely I can create the file in /tmp, just not in any other directory I've tried, even with permissions set such that user mysql should be able to write to the directory.
This is MySQL 5.0.75 running on Ubuntu.
Which particular version of Ubuntu is this and is this Ubuntu Server Edition?
Recent Ubuntu Server Editions (such as 10.04) ship with AppArmor and MySQL's profile might be in enforcing mode by default. You can check this by executing sudo aa-status like so:
# sudo aa-status
5 profiles are loaded.
5 profiles are in enforce mode.
/usr/lib/connman/scripts/dhclient-script
/sbin/dhclient3
/usr/sbin/tcpdump
/usr/lib/NetworkManager/nm-dhcp-client.action
/usr/sbin/mysqld
0 profiles are in complain mode.
1 processes have profiles defined.
1 processes are in enforce mode :
/usr/sbin/mysqld (1089)
0 processes are in complain mode.
If mysqld is included in enforce mode, then it is the one probably denying the write. Entries would also be written in /var/log/messages when AppArmor blocks the writes/accesses. What you can do is edit /etc/apparmor.d/usr.sbin.mysqld and add /data/ and /data/* near the bottom like so:
...
/usr/sbin/mysqld {
...
/var/log/mysql/ r,
/var/log/mysql/* rw,
/var/run/mysqld/mysqld.pid w,
/var/run/mysqld/mysqld.sock w,
**/data/ r,
/data/* rw,**
}
And then make AppArmor reload the profiles.
# sudo /etc/init.d/apparmor reload
WARNING: the change above will allow MySQL to read and write to the /data directory. We hope you've already considered the security implications of this.
Ubuntu uses AppArmor and that is whats preventing you from accessing /data/. Fedora uses selinux and that would prevent this on a RHEL/Fedora/CentOS machine.
To modify AppArmor to allow MySQL to access /data/ do the follow:
sudo gedit /etc/apparmor.d/usr.sbin.mysqld
add this line anywhere in the list of directories:
/data/ rw,
then do a :
sudo /etc/init.d/apparmor restart
Another option is to disable AppArmor for mysql altogether, this is NOT RECOMMENDED:
sudo mv /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/
Don't forget to restart apparmor:
sudo /etc/init.d/apparmor restart
I know you said that you tried already setting permissions to 777, but as I have an evidence that for me it was a permission issue I'm posting what I exactly run hoping it can help. Here is my experience:
tmp $ pwd
/Users/username/tmp
tmp $ mkdir bkptest
tmp $ mysqldump -u root -T bkptest bkptest
mysqldump: Got error: 1: Can't create/write to file '/Users/username/tmp/bkptest/people.txt' (Errcode: 13) when executing 'SELECT INTO OUTFILE'
tmp $ chmod a+rwx bkptest/
tmp $ mysqldump -u root -T bkptest bkptest
tmp $ ls bkptest/
people.sql people.txt
tmp $
MySQL is getting stupid here. It tries to create files under /tmp/data/.... So what you can do is the following:
mkdir /tmp/data
mount --bind /data /tmp/data
Then try your query. This worked for me after hours of debugging the issue.
You can do this :
mysql -u USERNAME --password=PASSWORD --database=DATABASE --execute='SELECT `FIELD`, `FIELD` FROM `TABLE` LIMIT 0, 10000 ' -X > file.xml
This problem has been bothering me for a long time. I noticed that this discussion does not point out the solution on RHEL/Fecora. I am using RHEL and I do not find the configuration files corresponding to AppArmer on Ubuntu, but I solved my problem by making EVERY directory in the directory PATH readable and accessible by mysql. For example, if you create a directory /tmp, the following two commands make SELECT INTO OUTFILE able to output the .sql AND .sql file
chown mysql:mysql /tmp
chmod a+rx /tmp
If you create a directory in your home directory /home/tom, you must do this for both /home and /home/tom.
Some things to try:
is the secure_file_priv system variable set? If it is, all files must be written to that directory.
ensure that the file does not exist - MySQL will only create new files, not overwrite existing ones.
I have same problem and I fixed this issue by following steps:
Operating system : ubuntu 12.04
lamp installed
suppose your directory to save output file is : /var/www/csv/
Execute following command on terminal and edit this file using gedit editor to add your directory to output file.
sudo gedit /etc/apparmor.d/usr.sbin.mysqld
now file would be opened in editor please add your directory there
/var/www/csv/* rw,
likewise I have added in my file, as following given image :
Execute next command to restart services :
sudo /etc/init.d/apparmor restart
For example I execute following query into phpmyadmin query builder to output data in csv file
SELECT colName1, colName2,colName3
INTO OUTFILE '/var/www/csv/OUTFILE.csv'
FIELDS TERMINATED BY ','
FROM tableName;
It successfully done and write all rows with selected columns into OUTPUT.csv file...
In my case, the solution was to make every directory in the directory path readable and accessible by mysql (chmod a+rx). The directory was still specified by its relative path in the command line.
chmod a+rx /tmp
chmod a+rx /tmp/migration
etc.
I just ran into this same problem. My issue was the directory that I was trying to dump into didn't have write permission for the mysqld process. The initial sql dump would write out but the write of the csv/txt file would fail. Looks like the sql dump runs as the current user and the conversion to csv/txt is run as the user that is running mysqld. So the directory needs write permissions for both users.
You need to provide an absolute path, not a relative path.
Provide the full path to the /data directory you are trying to write to.
Does Ubuntu use SELinux? Check to see if it's enabled and enforcing. /var/log/audit/audit.log may be helpul (if that's where Ubuntu sticks it -- that's the RHEL/Fedora location).
I had the same problem on a CentOs 6.7
In my case all permissions were set and still the error occured. The problem was that the SE Linux was in the mode "enforcing".
I switched it to "permissive" using the command sudo setenforce 0
Then everything worked out for me.