Rails error with Mysql 2 - mysql

This error showed up.
Mysql2::Error
Unknown MySQL server host '/tmp/mysql.sock' (2)
I already have the mysql.sock on my /tmp/ folder
eldiablo:tmp sbpipb$ pwd
/tmp
eldiablo:tmp sbpipb$ ls -l
total 8
-rw------- 1 sbpipb wheel 0 Nov 14 17:51 aprm0fjKv
drwx------ 3 sbpipb wheel 102 Nov 14 17:21 com.apple.launchd.1O4gD8GW17
drwx------ 3 sbpipb wheel 102 Nov 14 17:21 com.apple.launchd.xksWCs46sn
lrwxr-xr-x 1 root wheel 39 Nov 14 17:50 mysql.sock -> /Applications/MAMP/tmp/mysql/mysql.sock
srwxr-xr-x 1 sbpipb wheel 0 Nov 14 17:22 steam_chrome_shmem
I don't have any problem accessing mysql through the commandline though, and the password set on the db config is correct.
eldiablo:tmp sbpipb$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.5.38 Source distribution
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>

I've fixed it by putting the socket parameter in the database.yml
socket: /Applications/MAMP/tmp/mysql/mysql.sock
This fixed it!

Related

MySQL ignoring the options I set in ~/.my.conf

I am trying to turn off ONLY_FULL_GROUP_BY in my local ~.my.cnf options file.
Here are my system details:
$ sudo service mysql status
* /usr/bin/mysqladmin Ver 8.42 Distrib 5.7.25, for Linux on x86_64
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Server version 5.7.25-0ubuntu0.18.04.2
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/run/mysqld/mysqld.sock
Uptime: 19 min 35 sec
Threads: 1 Questions: 14 Slow queries: 0 Opens: 108 Flush tables: 1
Open tables: 27 Queries per second avg: 0.011`
~.my.cnf has the following content:
[mysqld]
key_buffer_size=32M
max_allowed_packet=512M
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,
ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
When I use "mysqld --help --verbose" this is what I see:
$ sudo mysqld --help --verbose
mysqld Ver 5.7.25-0ubuntu0.18.04.2 for Linux on x86_64 ((Ubuntu))
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Starts the MySQL database server.
Usage: mysqld [OPTIONS]
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
So my ~/.my.cnf is being read last meaning that it should override any settings made in previous files.
When I use "mysqld --print-defaults" to see what is being set, here's what I get:
$ sudo mysqld --print-defaults
mysqld would have been started with the following arguments:
--user=mysql --pid-file=/var/run/mysqld/mysqld.pid
-- socket=/var/run/mysqld/mysqld.sock --port=3306 --basedir=/usr
--datadir=/var/lib/mysql --tmpdir=/tmp --lc-messages-dir=/usr/share/mysql
--skip-external-locking
--bind-address=127.0.0.1 --key_buffer_size=16M --max_allowed_packet=16M
--thread_stack=192K --thread_cache_size=8
--myisam-recover-options=BACKUP --query_cache_limit=1M
--query_cache_size=16M --log_error=/var/log/mysql/error.log
--expire_logs_days=10 --max_binlog_size=100M --key_buffer_size=32M
--max_allowed_packet=512M
--sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,
ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
It would appear my settings have been actioned.
Using another method shows the same:
$ sudo mysqladmin variables | grep sql_mode
| sql_mode
ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,
ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
$ sudo mysqladmin variables | grep max_allowed_packet
| max_allowed_packet| 16777216
However, when I look at the settings of sql_mode and max_allowed_packet in mysql itself I see they still have their system default values:
$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.25-0ubuntu0.18.04.2 (Ubuntu)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select ##global.sql_mode;
+--------------------------------------------------------------------------+
| ##global.sql_mode |
+--------------------------------------------------------------------------+
| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE, |
| NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER, |
| NO_ENGINE_SUBSTITUTION |
+--------------------------------------------------------------------------+
mysql> select ##global.max_allowed_packet;
+-----------------------------+
| ##global.max_allowed_packet |
+-----------------------------+
| 16777216 |
+-----------------------------+
What am I'm doing wrong?
Your personal ~/.my.cnf can only affect programs run by you, for example mysql client or mysqldump, etc.
It does no good to write a section for [mysqld] in your personal ~/.my.cnf file, because your user is probably not the one who launches mysqld.
You could declare your preferred sql_mode for your own sessions in the MySQL client by writing the option into a [client] section:
[client]
max_allowed_packet=512M
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,
ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
But [client] only applies to MySQL tools like mysql and mysqldump. It doesn't affect any of your own apps, like if you code something in Java, Python, Ruby, or PHP, etc.
If you want an option to affect all clients, including your apps, you must apply the option in the global MySQL Server config, which is probably /etc/my.cnf as described in the other answer.
You can also change many global options dynamically without restarting mysqld. I often do this right after I edit the /etc/my.cnf file, so I can get the change without interrupting service.
mysql> SET GLOBAL sql_mode='...whatever...';
Final note: I recommend NOT disabling ONLY_FULL_GROUP_BY. That sql_mode is a useful way to prevent bogus query results. It's much better to keep that sql_mode enabled, and fix your SQL queries so they don't cause errors.
mysqld usually runs as its own user mysql, so ~/.my.cnf is meaningless unless it is in the home directory of the mysql user. For server configurations, you typically put settings in the /etc/my.cnf file or /etc/my.cnf.d depending on your mysql version.

how to find securely all mysql databases on a linux server

The post's title says almost everything:
How do I get a list of all mysql databases on a linux server?
I have read somewhere that there could be restrictions on the view a mysql user has on the list of available databases.
But I need a complete list of all mysql databases installed on a particular linux server (OpenSuse 13.1 in this case).
You will need to use SHOW DATABASES
SHOW {DATABASES | SCHEMAS}
[LIKE 'pattern' | WHERE expr]
SHOW DATABASES lists the databases on the MySQL server host. SHOW
SCHEMAS is a synonym for SHOW DATABASES. The LIKE clause, if present,
indicates which database names to match. The WHERE clause can be given
to select rows using more general conditions
However, you can see only those databases for which you have some kind of privilege, unless you have the global SHOW DATABASES privilege.
Another alternative is using mysqlshow client.
The mysqlshow client can be used to quickly see which databases
exist, their tables, or a table's columns or indexes.
You list all databases by executing:
mysql -u<username> -p<password> -e"SHOW DATABASES"
If you do not have access to the mysql server you could also check which databases exists by checking the /var/lib/mysql folder, which will contain a separate folder for each database:
ls -l /var/lib/mysql
total 28692
-rw-r--r-- 1 mysql mysql 0 May 24 2017 debian-5.5.flag
-rw-rw---- 1 mysql mysql 5242880 Oct 6 16:50 ib_logfile0
-rw-rw---- 1 mysql mysql 5242880 Jul 10 2015 ib_logfile1
-rw-rw---- 1 mysql mysql 18874368 Jan 17 2018 ibdata1
drwx------ 2 mysql mysql 4096 May 24 2017 mysql
-rw-rw---- 1 mysql mysql 6 May 24 2017 mysql_upgrade_info
drwx------ 2 mysql mysql 4096 May 24 2017 performance_schema
drwx------ 2 mysql mysql 4096 Jul 10 2015 scotchbox
drwx------ 2 mysql mysql 4096 Jan 17 2018 wp
As you can see in the above output there is 4 databases: mysql, performance_schema, scotchbox and wp.

zabbix can't connect to local MySQL server

When I start zabbix server ,the log show below:
# tail 300f /tmp/zabbix_server.log
[Z3001] connection to database 'zabbix' failed: [2002] Can't connect to local MySQL server through socket '/usr/local/mysql/tmp/mysql.sock'
my mysql is working and mysql's acount(zabbix) is working;
[root#localhost data]# ps aux |grep mysql
root 49035 0.0 0.0 113264 1616 pts/2 S 17:00 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --user=mysql
mysql 49170 0.0 5.5 1274804 215428 pts/2 Sl 17:00 0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/var/lib/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock
root 49628 0.0 0.0 112660 972 pts/2 S+ 17:22 0:00 grep --color=auto mysql
[root#localhost data]# /usr/local/mysql/bin/mysql -u zabbix -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.20 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| zabbix |
+--------------------+
2 rows in set (0.00 sec)
mysql>
the sock is here:
[root#localhost data]# cd /var/lib/mysql/
[root#localhost mysql]# ll
total 188504
drwxr-xr-x 2 mysql mysql 4096 Jan 24 12:30 mysql
srwxrwxrwx 1 mysql mysql 0 Jan 24 17:00 mysql.sock
-rw------- 1 mysql mysql 6 Jan 24 17:00 mysql.sock.lock
drwxr-xr-x 2 mysql mysql 8192 Jan 24 12:30 performance_schema
drwxr-xr-x 2 mysql mysql 12288 Jan 24 15:12 zabbix
[root#localhost mysql]#
my zabbix_server.conf
LogFile=/tmp/zabbix_server.log
DBName=zabbix
DBUser=zabbix
DBPassword=123456
what something wrong,please help me.
thank you so much at first
It looks like your DB socket is /var/lib/mysql/mysql.sock.
So you need to configure zabbix_server.conf for that:
DBSocket=/var/lib/mysql/mysql.sock
Doc: https://www.zabbix.com/documentation/3.4/manual/appendix/config/zabbix_server
Install like this
useradd zabbix
yum install net-snmp-devel libxml2-devel libcurl-devel
./configure --prefix=/usr/local/zabbix-3.4.6/ --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2
make
make install
cp /home/zabbix/zabbix-3.4.6/misc/init.d/fedora/core/zabbix_server /etc/init.d/
mysql add account:
create database zabbix character set utf8;
grant all on zabbix.* to zabbix#localhost identified by '123456';
flush privileges;
use zabbix;
source /home/zabbix/zabbix-3.4.6/database/mysql/schema.sql
source /home/zabbix/zabbix-3.4.6/database/mysql/images.sql;
source /home/zabbix/zabbix-3.4.6/database/mysql/data.sql;
exit;
Just restart the server where Zabbix is running.

MySQL first time create database error

So I have just installed linux and started messing around with apache,php,mysql and I have this error when creating database. I was unable to find an answer so i hope you guys can help me.
max#MaxLNX:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 67
Server version: 5.5.47-0ubuntu0.14.04.1 (Ubuntu)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database firstdb;
ERROR 1006 (HY000): Can't create database 'firstdb' (errno: 13)
Error means that your mysql server doesn't have enough space.
Check the file system size, and remove unwanted software(s),or files.
There may be a permissions issue with the MySQL data directory. You could try setting the permissions as follows (adjust the path to your data directory)
chown -R mysql:mysql /usr/local/mysql/data
reply if it worked
Try using "sudo". On a Linux system, "sudo" means "superuser" and should help you gain access to make a database. Try this in your terminal:
sudo mysql -u root -p

mysqld starts properly but i am not able to access it on rhel5

mysqld starts properly but i am not able to access it on rhel5, when i enter mysql command it return nothing, but when i enter /usr/bin/mysql it starts properly
[root#192 log]# service mysqld stop
^[[A^[[Stopping mysqld: [ OK ]
[root#192 log]# service mysqld start
Starting mysqld: [ OK ]
[root#192 log]# mysql
^Z
[2]+ Stopped mysql
[root#192 log]# mysql
^Z
[3]+ Stopped mysql
[root#192 log]# /usr/bin/mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1912
Server version: 5.1.61-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> \q
any help to fix this issue.