From my point of view, @Mr.Brownstone answer is only partially correct.
The backtick ` is used in MySQL to delimit literals that represent identifiers (not strings).
This allows you to use not usually accepted characters like spaces, reserved words, etc. as identifiers. For example:
SELECT * FROM `Strange table name`;
Also important is that it also ...
I am not sure this
SHOW STATUS LIKE 'Ssl_cipher';
has been changed in later versions. For me even if I am not using SSL, it shows SSL: Cipher in use is DHE-RSA-AES256-SHA for me.
You can use following to get confirmed SSL is using or not.
ubuntu@ip-111-22-3-444:~$ mysql -h 220.127.116.114 -u dbuser --ssl-mode=VERIFY_IDENTITY -p
ERROR 2026 (...
SELECT a.aircraftid 'Aircraft ID',
FROM aircraft a
JOIN service s
ON a.aircraftid = s.serviceid
GROUP BY a.aircraftid
HAVING COUNT(s.serviceid) > ( SELECT COUNT(serviceid) / COUNT(DISTINCT aircraftid)
FROM service )
ALTER TABLE myDatabase.myTable
ADD COLUMN age INT
AS (FLOOR(((CURRENT_DATE + 0) - (birth_date + 0)) / 10000))
More about generated columns read at MySQL 8.0 Reference Manual / ... / ALTER TABLE and Generated Columns.
The Slave purges old log files on its own. No problem.
The Master does not have a perfect way to get rid of old binlogs.
The Master can't remove an old binlog until all the slaves have copied it to their relay logs. But the Master neither has a list of Slaves, nor does it know where each is in the copying process.
expire_logs_days works pretty well, but ...
Here's how to identify which 'bad' query to fix that will give you the most bang for the buck: The slowlog plus pt-query-digest. More details here: http://mysql.rjweb.org/doc.php/mysql_analysis#slow_queries_and_slowlog
I rarely need to go down the list more than 3 items to make a dramatic improvement.
If you are weak on knowing what indexes to add, don'...
Use set-environment command:
systemctl set-environment MYSQLD_OPTS="--skip-log-bin=1"
Next, reload configuration files and restarted the server using the
systemctl restart mysqld
Next check the value of log_bin global variable:
mysql> SELECT * FROM performance_schema.global_variables WHERE VARIABLE_NAME IN (...
This is not a complete answer, but I need 50 rep to comment. Check out this similar question - > https://stackoverflow.com/questions/6000336/how-to-debug-lock-wait-timeout-exceeded-on-mysql . The first two answers have some steps you can follow to nail down what query is causing the lock and a possible resolution with setting your innodb_lock_wait_timeout ...
You don't need all binary logs from the master. Just the ones that your slave hasn't read yet.
On your slave you can do show slave status\G. Look for the lines Master_Log_File and Relay_Master_Log_File. The first is the binary log file, that your master is using, the second is the log file that your slave is currently reading.
You can then delete all ...
The queries are bad
Then they need fixing. You could add extra hardware but you will get linear improvements at best, fixing the queries could potentially give several orders of magnitude of improvement by removing huge scans and such. Though I'm only guessing here as we have no information about the actual queries.
and there are far too many of them to ...
Identify all corrupted tables using myisamchk
# myisamchk /var/lib/mysql/bugs/*.MYI >> /tmp/myisamchk_log.txt
myisamchk: error: Wrong bytesec: 0-0-0 at linkstart: 18361936
MyISAM-table 'attach_data.MYI' is corrupted
Fix it using switch "-r" or "-o"
myisamchk: warning: 1 client is using or hasn't closed the table properly
MyISAM-table 'groups.MYI' is ...
Of course you will see your terminal running the grep command .. that's pretty much to be expected. Please learn some console basics (either mac os or free bsd related as that is the underlaying system that mac os builds on )
If ps -> grep really only shows its own instance then there is nothing else with "mysql" in its process name.
Which pretty much ...
After further research it seems this is actually a bug.
Instead of directly reverse-engineering your database,
-create a new model
-save all your code in an .sql file
-while in the model tab go to file-import-reverse engineer create script
-check "place imported objects on diagram" and execute and there you go
Still unsure why the first above example ...
what is wrong with this code?
Wrong point is:
WHERE ... Relationship='Son' AND NOT Relationship='Daughter'
The conditions are applied to THE SAME RECORD. So when Relationship is equal to 'Son' then it is not equal 'Daughter' in this record automatically.
The conditions do not check any another record. So if a record where Relationship='Son' exists then ...
By "source file", do you mean the source command in the commandline tool mysql? If so, you need to kill that client, not the individual commands in PROCESSLIST.
Go to the OS's task manager. (You may need to be root.)
# ps -axl | grep mysql (or other args of your picking)
# kill -9 1234567 (using the PID from the ps)
You can use exists and not exists
from employee e
where exists (
select * from dependent where ssn = e.ssn and relationship = 'Son'
and not exists (
select * from dependent where ssn = e.ssn and relationship = 'Daughter'
You can also achieve this with a left join
from employee e
left join dependent d
If you are using a older MySQL versions like 5.1 - 5.7 , you need to use MySQL user variables as these MySQL versions does not support window functions and or common table expressions ..
I ported the answers of @Akina and @mustaccio and the fiddle of Akina
to a MySQL 5.1+ working query.
Warning as MySQL 5.1 to MySQL 5.7 does not use window functions and ...
How to enumerate records in contacts table within contact_group_id groups (emulate ROW_NUMBER) starting with 0:
COUNT(t2.contact_id) - 1 row_number
FROM contacts t1
JOIN contacts t2 ON t1.contact_group_id = t2.contact_group_id
AND t1.contact_id >= t2....
Depending on the size of the table, this variant of Akina's solution might perform a little better by calculating both running total and full total of volume in one go:
WITH cte AS (
SUM(volume) OVER (ORDER BY price ASC) running,
SUM(volume) OVER (ORDER BY price ASC
RANGE BETWEEN UNBOUNDED PRECEDING AND ...
That depends. If the test database on the Master was never in use, then the slave won't care. As long as the slave is not a master to another server, then you are OK.
If the slave has binary logging enabled, the database will just get created and dropped and a record of it would be in the binary logs of the slave.
Besides a test database would not be in ...
the rows with the lowest prices whose sum of volumes is less or equal to 10% of total volume. I need the average price of those rows
WITH cte AS ( SELECT price, SUM(volume) OVER (ORDER BY price ASC) summ
FROM sourcetable )
WHERE summ <= 0.1 * ( SELECT MAX(summ)
FROM cte )
In my situation slave replication coordinates were broken and I fixed this by resetting my slave and connect my slave to master by new coordinates without any data loss.
First, check if your slave gtid_slave_pos is differing from other slaves or master gtid_current_pos:
# on master
Putting parentheses in a BETWEEN leads to strangenesses:
date between (x and y) and filter1 = filter2
is treated as
(date between (x and y) and filter1) = filter2
BETWEEN expects 2 'arguments'; you have given it (1) (x and y), which returns true or false, which are numerically 1 or 0, and filter1.
The result of that (probably 0) is then compared: ...
total_hours is not visible for GROUP_CONCAT. Either use the expression behind total_hours (like @Rick-James does) or nest the query:
SELECT ..., GROUP_CONCAT(total_hours SEPARATOR ',') as real_hours
SELECT u.id ,tc.id as timecard_id, tc.week, tc.year, tc.status, u.first_name,
u.last_name, efv.value as staffasap, p.name, ti.paycode_id
No parentheses after in either of the places you used them.
[CONSTRAINT [symbol]] FOREIGN KEY
REFERENCES tbl_name (key_part,...)
[MATCH FULL | MATCH PARTIAL | MATCH SIMPLE]
[ON DELETE ...
You're correct in that the most common way to join two tables is to use a foreign key referencing a primary key. But it is not a requirement. The SQL will work (i.e. will by syntactically correct) for any two columns you wish to use in your JOIN clause, as long as the columns' types can be coerced into something comparable. The question is, will the ...
Get rid of @num_rows and @i; you can loop without counting. There are lots of examples floating around.
You must construct the query something like
SET @stmt := CONCAT('SELECT "', col_name, '", ' MIN(', col_name, '), ',
' MAX(', col_name, ')',
' FROM ', tbl_name');
The intent is to ...
The only thing that worked for me was to edit the my.ini file using Notepad++ ... do NOT use Windows Notepad as any change will stop mysql from starting.
I would guess this is because mysql fails to parse the file, so uses internal defaults which are no good as its looking for mysql master db in 'program files'.
The updating of secondary indexes (INDEXes other than PRIMARY KEY) happens later. Such changes are stored in the Change Buffer; they are actually written to disk later in a more efficient way than trying to do them as the rows are being inserted. You will see both CPU and I/O activity.
The net effect should be that your LOADs and SELECTs ...
The way the query is written, and the way IsDeleted is implemented, make the use of any index on IsDeleted useless. (Akina's comment explains h
If you have INDEX(UpdatedDate) then that index may help in the query. (Please provide EXPLAIN SELECT ....) But, if there are a lot of rows that fail that IsDeleted test, then it would have to scan a lot of rows ...
You can create timestamp in SYSTEM timezone with:
FROM_UNIXTIME(timestamp_in_seconds) -- This is a number, not a datetime
To convert back to a timestamp you can use UNIX_TIMESTAMP function.
This sample demonstrate how to generate random datetime based on starting point. It give you only correct timestamps:
select FROM_UNIXTIME(UNIX_TIMESTAMP('2016-03-27 ...
The old way of adding a Slave might be best:
Stop mysqld on an existing Slave (Replica)
Copy the disk (or at least all of MySQL's stuff)
Change the server_id
See if something in the Master contains a list of servers in the topology; if so, augment it
Start mysqld on both replicas.
CREATE TABLE users ( id PRIMARY KEY, ... );
CREATE TABLE groups ( leader_id REFERENCES users (id),
member_id REFERENCES users (id) );
The keys (including primary) and constraints in groups are dependent by:
does the user may be a member of one group only, or of a lot of groups;
does the group leader may be a member of ...
Try using the funtion max for the fields value and date, also apply `GROUP BY to id_item
SELECT a.id_item, a.value , max(b.date) as date
FROM tb_purchase_item a
LEFT JOIN tb_purchase b ON b.id = a.id_purchase
LEFT JOIN tb_sheet_item c ON c.id_item = a.id_item
LEFT JOIN tb_sheet d ON d.id = c.id_sheet
WHERE d.id = :id_sheet
GROUP BY a....
If B.field1 has a collation ending with _ci, then the UPPER is not needed; get rid of it.
Then you need INDEX(field1); do you have it?
And what about the ...? So far, I see no use for including C in the query.
Have the primary key in place, but not the secondary keys. When finished loading, add all the secondary keys in a single ALTER statement.
I have not done that particular task, so I dont speak from experience.
There have been changes over the years in how ALTER works. Doing multiple alters at once used to be optimal. But with online/instant/etc ...
Brackets have the highest priority.
select * from countries where date between (x and y) and filter = filter and choosen like '%col%';
-- step 1
select * from countries where date between (x and y) and filter = filter and (choosen like '%col%');
-- step 2
select * from countries where (date between (x and y) and filter) = filter and (choosen ...
I answer by myself. In short, sql syntax above is correct, so how to query mysql tables with regular expressions? Exactly like I did.
The reason why it didn't work, is regexp syntax being too 'complex' for mysql.
I found out that mysql doesn't support the full syntax possibilities of standard regular expressions. I must use simpler symbols/constructs. So ...
I think you posted on here the other day asking a similar question.
1) Don't use mysql start, use sudo service mysql start or similar.
2) You don't want to change the permissions on /var/log/mysql - Administer Ubuntu properly and change to the mysql user in order to view them, using sudo su - mysql
Do not attempt to start MySQL as your user, or hack the ...
Use user-defined variable for to convert the date value from dd\mm\YYYY format to the date/datetime datatype value during import:
LOAD DATA INFILE
(field1, field2, ..., @date, ...)
SET datefield = STR_TO_DATE(@date, '%d\/%m\/%Y');