Main user can't edit or run script, cronfile in SSH - mysql

I have a VPS with Intel XeonCPU E3-1270 V2 # 3.50GHz running on OpenVZ Webuzo + nginx
I used to edit cronjobs or other files as the main user via SSH. But it seems that I've lost all the privilege after restarting MySQL to fix a sudden CPU usage spike.
I get these errors when opening, accessing or saving files:
"user is not in the sudoers file. This incident will be reported.”
[user#vm root]$ php info.php
Could not open input file: info.php
[user#vm root]$ vi hello.text
E212: Can't open file for writing"
And when I run crontab -e and crontab -l, they return nothing. They just show:
[user#vm root]$ crontab -e
[user#vm root]$
Not sure if it has anything to do with me restarting the server, httpd, and MySQL. What should I do to get back the privilege back to the main user?

[user#vm root]$ php info.php
Could not open input file: info.php
[user#vm root]$ vi hello.text
E212: Can't open file for writing"
It seems you are logged in as the "user" and your current location is /root.
You are allowed to write contents to /home/user and not /root if you are logged in as the "user".
And when I run crontab -e and crontab -l, they return nothing.
Possibly your CRON service is not responding for some reason.
Re-installing the service will be a quick fix.
What should I do to get back the privilege back to the main user?
su -
and fill in your root users' password to get you privileges.
Good Luck

Related

mysqlbackup: ERROR: Opening of file /var/lib/mysql/ibdata1 failed. Error code: 13, Permission denied

Im trying to backup my database using mysqlbackup, but I keep getting this error and I don't know why is refering to a Permission denied error.
I already turned off SeLinux because I thought that would be the cause but there's nothing in the selinux log either, also I can log in to mysql using the normal command: mysql -uuser -ppassword.
The whole password with the output can be seen here: http://pastie.org/10798013
This is because MySQLBackup requires that it be run as root to access needed resources. Normally you would simply run sudo mysqlbackup, but I believe that this does not work by default for this program.
The quickest thing to do in this case, is run the command as the root user. To do this, all you need to do is open a terminal and type:
sudo -s
You will be prompted for your password, then the terminal will show root#... instead of the normal user#.... This indicates that you are now root.
Now you can execute your code again:
mysqlbackup --compress --user=root --socket=/var/lib/mysql/mysql.sock --backup-dir=/home/user/backup backup
Once done, remember to log out of root by simply typing exit. Remember, do not use the root user unless you have no other choice; it is easy to accidentally change important files/folders unless you are sure of what you are doing.
Learn More
It is worthwhile to understand more about logging in as root, and even adjusting the configuration so that mysqlbackup does not require root, so here are some links:
MySQLBackup Permission Denied (Unix & Linux - StackExchange)
RootSudo (Ubuntu Wiki)
late response, but this precise error happens when trying to restore a differential/incremental backup when the mysql deamon is running
if you are able to connect to your database using the command
mysql -uuser -ppassword
then you're only able to restore full backups
if not, then you're able to restore differential/incremental backups, but no full
in other words: you should turn off your service ( net stop mysql-8.0 for me )

Can't login to unix mysql user

I'm trying to login to my mysql user created by the MySQL installation in bash shell.
So the command I'm trying to do is:
sudo -i -u mysql
But, it does nothing (nothing printed out in the console, not connected to any user whatsoever, etc...).
EDIT: The return value of the command is 1 though.
Here is the mysql user line in the /etc/passwd file:
mysql:x:89:89::/var/lib/mysql:/bin/false
I'm running on ArchLinux 64bit and the user I'm trying to connect to is local (no connection to a remote server whatsoever).
I'm trying to understand why I can login with any other user (like postgres, root, ...) but not mysql.
Hope you can help!
This is intended behaviour. When you compare the /etc/passwd line with other lines you'll notice that the user mysql has /bin/false setup as the shell while others have usually /bin/sh or sth. similar.
When you sudo to mysql you actually get a login for about a millisecond or so and then his "shell" gets executed. /bin/false immediately returns with rc=1 (that's the only purpose of the false command).
This is some kind of "trick" to prevent users from logging in as user mysql although the account is otherwise fully operational.
The user mysql may even have a valid password and be enabled but due to his odd shell setting you cannot login as him. Sometimes these technical users have /usr/bin/passwd set as their shell. Then you can only sudo to that user and change his password, nothing else.

MySQL root pwd is no more visible in the API Console

In Google Api Console
I have successfully created an instance using 'Click to Deploy' LAMP.
After Creation, the mysql root pwd was displayed for some moment in the API console, which I forgot to note it down and it is no more available in the API console.
Any idea on how to retrieve this mysql root pwd or to reset it again?
First log on to your system as the user that the mysqld server runs as. Locate the .pid file that contains the server's process ID. The exact location and name of this file depend on your distribution, host name, and configuration. Common locations are /var/lib/mysql/, /var/run/mysqld/, and /usr/local/mysql/data/.
Then send a kill command to the mysql process using the following command using the path name of your .pid file instead:
shell> kill cat /mysql-data-directory/host_name.pid
Create a text file containing the following statements replacing the password with your new one:
UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;
Write the UPDATE and FLUSH statements each on a single line.
Start the MySQL server with the special --init-file option:
shell> mysqld_safe --init-file=/home/me/mysql-init &
After the server has started successfully, delete /home/me/mysql-init.You should now be able to connect to the MySQL server as root using the new password. Stop the server and restart it normally.
For your reference the link to the MySQL documentation on this topic can be found here:
https://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html

Installing MySQL Workbench but File /etc/my.cnf doesn't exist

I managed to download the MySQL DMG archive to my OS (mac OS X). It works if I use the command line.
Now, I'm trying to install MySQL Workbench.
I've created MySQL Connection but once I'm testing the host machine settings, I get:
Checking command 'ps xa | grep "/usr/local/mysql.*/bin/[m]ysqld"'
Server detected as running
Check if /etc/my.cnf can be accessed
Operation failed: File /etc/my.cnf doesn't exist
I'm trying to find the file my.cnf and I get:
Didis-MacBook:~ Didi$ find . -type f -name "*my.cnf*"
find: ./perms/newdir: Permission denied
So I tried to create my own "my.cnf" by entering:
cd /usr/local/mysql/support-files/
sudo cp my-huge.cnf /etc/my.cnf
Then it asked for a password. I don't remember setting up a password.
So I typed:
/usr/local/psa/bin/admin --show-password
and get:
-bash: /usr/local/psa/bin/admin: No such file or directory.
I believe my password should be in /etc/passwd but I have no dir "etc" in my system!
I'm running out of ideas, can somebody help me please?
I figured it out:
Went to my terminal and typed:
passwd
Old password was blank
I created a new password (it was THAT simple)
I created a "etc" directory
I checked the files under /usr/local/mysql/support-files/ and saw my cnf file was actually named my-default.cnf and not my-huge.cnf like the developer at the MySQL site.
So I typed: sudo cp my-default.cnf /etc/my.cnf
went back to the Workbench and it FINALLY said:
Testing host machine settings is done.
The MySQL Server installation on OS X does not include a cnf file, so it is normal that you get the warning. Nonetheless you can continue creating the connection without problems (ignore the warning). When you start MySQL Workbench afterwards and try to manage the configuration of the server, you will get another warning, but you can continue and MySQL Workbench creates the cnf file for you. No need to do all that manually.
I met this problem too. I just clicked the continue button until i was at "Review remote management settings" step, and stop here click "change parameters", then continue. At "Path to configuration file" choose the path point to my-default.cnf. Then check path, it works

Expect scripting: remote database backup automation

I'm looking for a kind of remote database backup automation.
Then, I came across a scripting language which commonly used for administrative tasks, "Expect scripting" and I believe it could serve my purpose very well.
what I'd like to do is I want to perform login to a remote server using the following bash script from my local linux box. (supposed everything has been set properly, SSH authentication via generated key pair, so no password is required)
For the most important part, I'd like to send a mysqldump command to perform backup for my database on that server.
#!/usr/bin/expect
set login "root"
set addr "192.168.1.1"
spawn ssh $login#$addr
expect "#"
send "cd /tmp\r"
expect "#"
send "mysqldump -u root -ppassword my_database > my_database.sql\r"
expect "#"
send "exit\r"
The only problem I found here was after the line send "mysqldump -u root....... ".
It was never waiting until the process to finish, but immediately exit the shell with 'send "exit\r"' command line.
what do I do to make it waits until mysqldump command finish and log off the SSH properly?
I don't know the answer to your question: add exp_internal 1 to the top of the program to see what's going on.
However, since you have ssh keys set up, you don't really need expect at all:
ssh $login#$addr 'cd /tmp && mysqldump -u root -ppassword my_database > my_database.sql'