snmptrapd doesn't log in mysql - mysql

I am trying to log snmp traps to mysql db, but unfortunately without results.
OS - Debian
Net-SNMP v.5.7.3
MySQL 5.1
I am using snmptrapd and did the configuration from here
here is my snmptrapd.conf:
authCommunity log public
sqlMaxQueue 1
sqlSaveInterval 9
I did
./configure --with-defaults --with-mysql
as in the manual . Then
make
make install
Here is my ~/.my.cnf:
[snmptrapd]
user=snmp
password=******
host=localhost
my /default/snmpd:
#export MIBS=
#SNMPDRUN=yes
#SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid'
TRAPDRUN=yes
TRAPDOPTS='-Lsd -p /var/run/snmptrapd.pid'
SNMPDCOMPAT=yes
I have exact DB schema as in the manual
I have success logging into syslog, but nothing in mysql. Even mysql log doesn't show anything. It's looks like snmptrapd doesnt reach MySQL
Can anyone give me idea what i am missing?

I found the solution of my problem.
I have been changing /etc/snmp/snmptrapd.conf and mysql logging didnt worked. I just find that there is another snmptrapd.conf in /usr/local/etc/snmp/snmptrapd.conf that i fill with the configuration showed in my first post.
So far it works!

I have found an article for you:
http://ethertype.blogspot.com/2015/10/logging-snmp-traps-to-mysqlmariadb.html
You must set your database name as "net_snmp".

Related

How do you start a MySQL server on linux?

Pretty simple question here. I just want a SQL database on my version of Kali linux so I can practice SQL.
I opened the command line and entered tried to start mysql and get an error.
> mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
I also made sure it was already installed using apt-get.
What are the steps I need to take to be able to make a database with tables and data that I can query?
I don't know about Kali, but on Ubuntu it would be
$ sudo service mysql start
Once that command returns, the mysqld service has started, so you can use the mysql client to connect to it.
Of course, you also have to make sure you have the mysql-server package installed, not just mysql-client and mysql-common, and that you've initialized the database instance. Complete post-installation instructions can be found in the official documentation, but the short version is
Make sure the installer has created the mysql user account. This is the account that will "own" the server process once it starts.
Change to your data directory. (I used the installer's default of /var/lib/mysql; you can change this by editing my.cnf.)
As root, execute the server daemon with the --initialize switch. Check whereis to determine the correct path, then
$ sudo /path/to/mysqld --initialize --user=mysql
This command will twiddle itself for a while, then display an automatically-generated password and exit. Once the command returns, the database instance has been initialized and the system tables created. You can now start the database instance normally (using service start), then log in as the database user root (which is not the same as the system user root) using the password from above, then change your password, create a new database user, log in as that user, create a user database, and start creating tables.
Again, the official documentation is the place to look for this; if any of the instructions in the official documentation differ from my instructions, you should ignore me and follow the official documentation's instructions.
If sudo service mysql start doesn't work for you, please try running mysqld_safe and don't kill the process. Use another tab to check the status of mysql service. This should solve your mysqld.sock issue.
If it doesn't work out, then please edit your my.cnf file and add the following:
socket=/var/lib/mysql/mysql.sock
And the permissions,
sudo chmod -R 755 /var/lib/mysql/
Hopefully, this should do it.
On my version of kali (2022-rolling), even though it's installed as MySQL, it's run as mariadb. To start it is:
sudo /etc/init.d/mariadb start
Try this
sudo service mysql start

MySQL - Can't connect to local MYSQL server...ERROR 2002?

Hi I've looked all over the internet to find an answer to this problem but nothing seems to work. I get the below problem when I try to log in to mysql on terminal in OSX El Capitan.
The server is running.
What should I do, I've spent 5 hours trying to figure this out before posting this. I cannot find the my.cnf file in /etc and I'm not sure what to do with it. Someone please help.
Edit:
I've downloaded and installed(just double clicking - no terminal) this:
When everything is installed and i go into /usr/local/mysql/bin/ and try mysql -u root -p I get the following error:
This is my my.cnf file in /etc:
When I do sudo /usr/local/mysql/bin/mysqld_safe I get this:
df -h returns this, could it be something to do with space?
If you feel more comfortable installing it through the GUI here is an instruction guide on how to do that.
http://dev.mysql.com/doc/refman/5.7/en/osx-installation-pkg.html
Make sure you install the MySQLStartupItem.pkg and MySQL.prefPane. After you have done that you can verify your installation by opening up Terminal and running:
cd /usr/local
hitting enter then typing:
ls
hit enter again and verify the existence of two directories, one will just be MySQL and the other will be MySQL-(version number you installed).
At this stage I would restart your computer and then on restart the mysql server will start up.
Once it's restarted fire up terminal window again and type this:
/usr/local/mysql/bin/mysql -u root -p
EDIT
Open your /etc/my.cnf file and edit these two configurations.
[mysqld]
socket=/var/mysql/mysql.sock
[client]
socket=/var/mysql/mysql.sock
Hope this helps.

Table 'performance_schema.session_variables' doesn't exist

After upgrading MySQL to 5.7.8-rc
and loging to server I got error:
Table 'performance_schema.session_variables' doesn't exist
I can't find any solution for this. Can you help ?
I was able to log on to the mysql server after running the command #robregonm suggested:
mysql_upgrade -u root -p --force
A MySQL server restart is required.
The mysql_upgrade worked for me as well:
# mysql_upgrade -u root -p --force
# systemctl restart mysqld
Regards,
MSz.
mysql -u app -p
mysql> set ##global.show_compatibility_56=ON;
as per http://bugs.mysql.com/bug.php?id=78159 worked for me.
Since none of the answers above actually explain what happened, I decided to chime in and bring some more details to this issue.
Yes, the solution is to run the MySQL Upgrade command, as follows: mysql_upgrade -u root -p --force, but what happened?
The root cause for this issue is the corruption of performance_schema, which can be caused by:
Organic corruption (volumes going kaboom, engine bug, kernel driver issue etc)
Corruption during mysql Patch (it is not unheard to have this happen during a mysql patch, specially for major version upgrades)
A simple "drop database performance_schema" will obviously cause this issue, and it will present the same symptoms as if it was corrupted
This issue might have been present on your database even before the patch, but what happened on MySQL 5.7.8 specifically is that the flag show_compatibility_56 changed its default value from being turned ON by default, to OFF. This flag controls how the engine behaves on queries for setting and reading variables (session and global) on various MySQL Versions.
Because MySQL 5.7+ started to read and store these variables on performance_schema instead of on information_schema, this flag was introduced as ON for the first releases to reduce the blast radius of this change and to let users know about the change and get used to it.
OK, but why does the connection fail? Because depending on the driver you are using (and its configuration), it may end up running commands for every new connection initiated to the database (like show variables, for instance). Because one of these commands can try to access a corrupted performance_schema, the whole connection aborts before being fully initiated.
So, in summary, you may (it's impossible to tell now) have had performance_schema either missing or corrupted before patching. The patch to 5.7.8 then forced the engine to read your variables out of performance_schema (instead of information_schema, where it was reading it from because of the flag being turned ON). Since performance_schema was corrupted, the connections are failing.
Running MySQL upgrade is the best approach, despite the downtime. Turning the flag on is one option, but it comes with its own set of implications as it was pointed out on this thread already.
Both should work, but weight the consequences and know your choices :)
Follow these steps without -p :
mysql_upgrade -u root
systemctl restart mysqld
I had the same problem and it works!
As sixty4bit question, if your mysql root user looks to be misconfigured, try to install the configurator extension from mysql official source:
https://dev.mysql.com/downloads/repo/apt/
It will help you to set up a new root user password.
Make sure to update your repository (debian/ubuntu) :
apt-get update
If, while using the mysql_upgrade -u root -p --force command You get this error:
Could not create the upgrade info file '/var/lib/mysql/mysql_upgrade_info' in the MySQL Servers datadir, errno: 13
just add the sudo before the command. That worked for me, and I solved my problem. So, it's: sudo mysql_upgrade -u root -p --force :)
For my system the problem ended up being that I still had Mysql 5.6 installed and so the mysql_upgrade.exe from that installation was being called instead of the one for 5.7. Navigate to C:\Program Files\MySQL\MySQL Server 5.7\bin and run .\mysql_upgrade.exe -u root
sometimes mysql_upgrade -u root -p --force is not realy enough,
please refer to this question : Table 'performance_schema.session_variables' doesn't exist
according to it:
open cmd
cd [installation_path]\eds-binaries\dbserver\mysql5711x86x160420141510\bin
mysql_upgrade -u root -p --force

How to make mysql_install_db work?

I am new with MySql please help me out.
First to install MySql 5.5.7-rc i used this command->
sudo ./configure --prefix=/usr/local/mysql --with-plugin-partition --with-tcp-port=3308 --with-unix-socket-path=/tmp/mysql1.sock --with-debug
$sudo make
$sudo make install
Then when i am executing following command i am getting couple of errors.
$sudo ./mysql_install_db --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql/ --user=mysql
ERROR:::
Installing MySQL system tables...
connect: Connection refused
Installation of system tables failed! Examine the logs in
/usr/local/mysql/data for more information.
You can try to start the mysqld daemon with:
shell> /usr/local/mysql//bin/mysqld --skip-grant &
and use the command line tool /usr/local/mysql//bin/mysql
to connect to the mysql database and look at the grant tables:
shell> /usr/local/mysql//bin/mysql -u root mysql
mysql> show tables
Try 'mysqld --help' if you have problems with paths. Using --log
gives you a log in /usr/local/mysql/data that may be helpful.
Please consult the MySQL manual section
'Problems running mysql_install_db', and the manual section that
describes problems on your OS. Another information source are the
MySQL email archives available at http://lists.mysql.com/.
Please check all of the above before mailing us! And remember, if
you do mail us, you MUST use the /usr/local/mysql//scripts/mysqlbug script!
Then i tried '/usr/local/mysql//bin/mysql -u root mysql' and i found
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
But /tmp/mysql.sock and /var/run/mysqld/mysqld.sock don't exist. I checked it...
Please give some suggestion to overcome this problem.
even mysqld service is not being started..
"connect: Connection refused" means the server's not listening where it's expected to; I understand that an answer a year late might be a bit too late but one should start with what the distribution provides or the official builds and not a self-made source build of an RC of a quite complex product in the first place.
Maybe those hitting this question will find the accepted answer to that one useful: bash:scripts/mysql_install_db: No such file or directory

Macports mysql5 setup under Snow Leopard

I've managed to get my install all screwed up as I'm a newbie and messing up is what I'm good at.
1) Can anyone reference a credible set of setup instructions for this stuff?
2) Can I just uninstall and start from scratch (passwords and all) through macports? I tried and a bunch of mysql directories stuck around after the unistall, WTF!?
3) Where does mysqld.sock need to reside and what file settings do I need to apply to get it playing nice with php5 and apache2 ?
Does it live in /tmp or in /opt/local/var/run/mysql5/ ?
Do I need to configure /opt/local/etc/php5/php.ini? opt/local/var/db/php5/mysql.ini? /opt/local/etc/mysql5/my.cnf?
4) I've run > sudo -u mysql mysql_install_db5. If I run it again will it mess me up?
I ran mysqladmin -u root password 'mypw' and got an error saying the mysql could not connect through the socket. So does this mean my password is now set? Is there a way I can tell?
5) The syntax of the password statement changes from blog to blog. Is my password 'mypw' or mypw (without the quotes)? (My password is not actually mypw)
6) What are the appropriate commands to start and stop mysql? I DO NOT want it to start when my machine starts.
Thanks Jergason, that's tremendously helpful.
I'd really like to stay consistent with the macports installation of mysql since it limits the damage I can do to my machine.
So the outstanding questions now are...
1) What is the default socket location for the macports mysql install?
2) What are the appropriate commands to start and stop mysql? I DO NOT want it to start when my machine starts. Some blogs say to use launchctl -load others say sudo /path/mysql_safe5. If you havn't set the password (as I don't intend to) do you need to use the -user -p parameters?
3) What are the necessary directory ownerships and permissions to get macports mysql working. It doesn't seem that macports sets any of that.
Nerdling
Check /tmp for the MacPorts mysql socket
Not helpful. As previously stated, I understand that /tmp is the default location for the socket. My problem is that when I attempt to start mysql the socket does not materialize there, nor does it appear in /opt/local/var/run/mysql5/. This tells me I have a problem starting mysql, which means there is something wrong with the setup. What it could be, I don't know. I'm afraid I wasn't born with an a priori knowledge of such things.
-What SPECIFIC directory SHOULD the socket be in for the mysql5 install using macports under Snow Leopard?
If you're using 5 different sites' tips on how to run mysql and you're surprised you've gotten lost … well, I'll just leave it at try to follow just one site at a time and back out all changes before going to the next.
Not helpful. I did exactly what you're suggesting to begin with. What do you think I did, mix and match instructions from 5 blogs? This is why I asked about clean uninstalls. I wanted to know if a state change from a previous install could effect future "clean" installs.
-What SPECIFIC blog describes the confirmed-to-be-correct install procedure of mysql5 using macports under Snow Leopard.
I think the only problem you're having with MacPorts mysql (what problem are you having??) is that it's got a socket where you don't expect it and it's using a default configuration.
Not helpful. Me too, see my original post. I think the problem lies with how mysql is started (or isn't starting).
-Do you have any SPECIFIC suggestions on how to correct the problem?
This should have been explained after the install was completed by MacPorts.
Not helpful. It wasn't, or I didn't see it if it was. Maybe because I was using Porticus.
-Could you be more SPECIFIC? At WHAT point should I have seen WHAT message?
Please see ${prefix}/share/doc/mysql5/ for ideas and/or contact the developer list. Also consider contacting the maintainer of the port; they likely know the most about it since they manage it.
Not helpful. RTM, Google is your friend, and all that. Yep, went there first. Although I will admit I may have overlooked something as I'm not inclined to spend days reading some poorly written docs when I have other work to do to when I'm sure my problem is a simple one.
If you want to give me a SPECIFIC document that I may have overlooked, THAT would be helpful.
I was hoping for some simple, focused help like what Jergason provided. I (and others reading this) appreciate Jergason's willingness to convey his knowledge in order to accelerate the learning process of people new to various technologies. To him, the knowledge is basic, but to new-comers it's a massive time-saver. The true mark of intelligence is the understanding that technology knowledge is not a priori and that even basic help is of great help. Thanks again J-man.
I've just installed mysql5 myself, and since this is always a pain I've noted the process that I followed. This was done on Leopard, but I imagine the process is the same on Snow Leopard and Lion. It doesn't answer all the original questions, but at least it's something of a guide.
Installing Mysql
First, install mysql5 server with:
sudo port install mysql5-server
Just installing mysql5 doesn't install the server.
Pay attention to the console output, it includes instructions for setting up macports. You might want to copy and paste it to a text file. The following is based on it.
Instead of mysql5-server, you could use a port such as mysql55-server, mysql56-server, mariadb-server or percona-server to get a more recent version of mysql, or a fork. If you do, pay attention to the console output, as the following instructions are based on mysql5-server and will need to be adjusted to use the correct executables and paths.
If this is a new install, set up the database:
sudo -u _mysql mysql_install_db5
That outputs some generic instructions, which I don't think are entirely appropriate for macports. In my opinion the best way to load mysql5 as a daemon is to use macport's method:
sudo port load mysql5-server
As well as starting mysql5, this permanently loads it - it will run on boot up. To stop this later:
sudo port unload mysql5-server
If you don't want to run it as a daemon, you can run it at the command line:
sudo /opt/local/lib/mysql5/bin/mysqld_safe
Check that it's running by logging in at the command line:
mysql5 -u root -p
By default, the password is empty, so just press enter when prompted. To set a root password:
/opt/local/lib/mysql5/bin/mysqladmin -u root password 'correct horse battery staple'
Instructions for setting up both macports php and the native php installation follow.
Setup Macports PHP
Assuming you've already got macports php installed and running. You need to install php5-mysql (or something like php54-mysql depending on which version of php you're using):
sudo port install php5-mysql
This installs the mysql, mysqli and pdo drivers.
Now look in your /opt/local/etc/php5 directory, if you don't already have a php.ini configuration file copy either php.ini-development or php.ini-production to php.ini. Now edit php.ini and search for the appropriate lines to add:
pdo_mysql.default_socket=/opt/local/var/run/mysql5/mysqld.sock
and:
mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock
and:
mysqli.default_socket = /opt/local/var/run/mysql5/mysqld.sock
If you don't want to configure these, you can set them explicitly in your php script when you connect.
If you're having trouble connecting you might want to look at the other nearby settings, and compare with php.ini-development and php.ini-production to see what's been changed.
Then use the script below, or something similar to test that you can connect with php.
Setup System PHP
OS X's php comes with mysql and mysqli support built in (but not pdo), so all you need to do is set the macport unix socket. The default location is /opt/local/var/run/mysql5/mysqld.sock. Find the correct place in /etc/php.ini (if you don't have it already, copy it from /etc/php.ini.default) to add:
mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock
and:
mysqli.default_socket = /opt/local/var/run/mysql5/mysqld.sock
If you don't want to configure these, you can set them explicitly in your php script when you connect.
Test Script
Here's a php script to check that it can connect. Obviously, you won't normally use the root account in your php scripts so you might want to first create another mysql account for testing the connection. The PDO connection won't work for native php since that doesn't have PDO drivers.
<?php
$username = 'root';
$password = 'correct horse battery staple';
/* Try mysql: */
$connection = mysql_connect('localhost', $username, $password);
if ($connection === FALSE) {
echo "Error connecting using mysql.\n\n";
echo "Error ".mysql_errno().": ".mysql_error()."\n\n";
}
else {
echo "Connected using mysql.\n\n";
mysql_close($connection);
}
/* Try mysqli: */
$connection = mysqli_connect('localhost', $username, $password);
if ($connection->connect_error) {
echo "Error connecting using mysqli:\n\n";
echo "Error ".$connection->connect_errno.": ".$connection->connect_error."\n\n";
}
else {
echo "Connected using mysqli.\n\n";
$connection->close();
}
/* Try pdo:
* Won't work for the version of php supplied with OS X. */
try {
$pdo = new PDO('mysql:host=localhost', $username, $password);
echo "Connected using PDO.\n\n";
$pdo = null;
}
catch(PDOException $e) {
echo "Error connecting using PDO:\n\n";
echo "Error ".$e->getCode().": ".$e->getMessage()."\n\n";
}
I've just run into the same issue myself. To get my MySQL working, I simply had to do
sudo chmod -Rf 777 /opt/local/var/db/mysql5
The attempt to do sudo -u _mysql mysql_db5 failed, but I could then do
mysqladmin -u root password the_new_password
without any problem.
If you don't want MySQL to start automatically when you turn the machine on, simply do this:
sudo launchctl unload -w /Library/LaunchDaemons/org.macports.mysql5.plist
Then to start/stop MySQL:
start:
sudo /opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper start
stop:
sudo /opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper stop
Hope this helps.
1)Hivelogic has a great walkthrough on compiling mysql for Snow Leopard from the source. It is not actually that difficult, and if you do it yourself you will know where it is.
2) You should be able to just run sudo port uninstall mysql5. It may yell at you about dependencies. If so you will have to uninstall those first. Uninstalling MySQL should remove all config settings including passwords.
3) Where does mysqld.sock need to reside and what file settings do I need to apply to get it playing nice with php5 and apache2 ? The location of mysqld.sock is less important than the path to it. You set the path to mysqld.sock in your php.ini file. If you have a php.ini file in /opt/local/bin, then you installed the macports version of php. You can use that one, or you can use the default Apple version. Either way, you need to configure the php.ini file in order to tell your php installation where to go to use it. There should be a line in your php.ini file that says
mysql.default_socket = <whatever>
If it is not there, you can add it. You should set this line equal to the location of your mysqld.sock. Mine looks like this:
mysql.default_socket = /Applications/MAMP/tmp/mysql/mysql.sock
Your Apache configuration
4) I've run > sudo -u mysql mysql_install_db5. If I run it again will it mess me up? I ran mysqladmin -u root password 'mypw' and got an error saying the mysql could not connect through the socket. So does this mean my password is now set? Is there a way I can tell? If you could not connect to the socket, then your password was not set.
5) The syntax of the password statement changes from blog to blog. Is my password 'mypw' or mypw (without the quotes)? (My password is not actually mypw) You don't need the quotes around the password in the command line.
Check /tmp for the MacPorts mysql socket.
If you're using 5 different sites' tips on how to run mysql and you're surprised you've gotten lost … well, I'll just leave it at try to follow just one site at a time and back out all changes before going to the next.
I think the only problem you're having with MacPorts mysql (what problem are you having??) is that it's got a socket where you don't expect it and it's using a default configuration. This should have been explained after the install was completed by MacPorts. Please see ${prefix}/share/doc/mysql5/ for ideas and/or contact the developer list.
Also consider contacting the maintainer of the port; they likely know the most about it since they manage it.
the php.ini being used on the command line may be different than the one being used by apache
You can check this with
phpinfo.php
<?php
phpinfo();
?
by doing a
php phpinfo.php | grep php.ini
if it shows
Configuration File (php.ini) Path => /opt/local/etc/php5
and the test script of Daniel James answer (saved as testconnect.php) also fails
then you might want to fix by creating a symbolic link:
/opt/local/etc/php5>sudo ln -s /etc/php.ini php.ini
after that the testconnect should work
php testconnect.php
Connected using mysql.
Connected using mysqli.
Connected using PDO.
I figured out the problem. Despite the fact that Apache was not running, for some reason Apache was blocking MySQL from running (and thus from creating the socket). (Yea, weird right?) Before I ran the install, I issued the command to stop apache, then the install went swimmingly. Even now, before I start MySQL, I first have to tell Apache (which is not running) to stop.
And just for the record, I know it's not running because I get
"httpd (no pid file) not running"
I'm not having it run automatically on start up or any bone-head crap like that.
I'll try to write up a walk-through so that no one else has to go through this BS.
When installing php5 via macports the package doesn't come automatically with mysql extension, so it cannot connect to mysql via php (but you probably can through command line).
Let's check first if your mysql is running properly:
mysqladmin5 -uroot -pYOURROOTPASSWORD ping
If it's alive, you can verify all the variables by:
mysqladmin5 -uroot -pYOURROOTPASSWORD variables
You should see your "socket" location is defined as
/opt/local/var/run/mysql5/mysqld.sock
Using macports install missing components in 2 minutes... here's how:
sudo port install php5-mysql
To use mysqlnd with a local MySQL server, edit /opt/local/etc/php5/php.ini and set
mysql.default_socket, mysqli.default_socket and pdo_mysql.default_socket
to /opt/local/var/run/mysql5/mysqld.sock
Then to restart your Apache type:
sudo /opt/local/apache2/bin/apachectl -k restart
Now everything should be up and running properly. Hope that helps.