Langsung ke konten utama

Postingan

Menampilkan postingan dengan label mysql

How To Get row_number in MySQL

 https://ubiq.co/database-blog/how-to-get-row_number-in-mysql/ SELECT t.*, @rownum := @rownum + 1 AS rank FROM sales t, (SELECT @rownum := 0) r order by amount desc; +------+---------------------+--------+------+ | id | order_date | amount | rank | +------+---------------------+--------+------+ | 1 | 2021-02-02 08:15:00 | 250 | 1 | | 10 | 2021-02-02 11:15:00 | 250 | 2 | | 5 | 2021-02-02 09:30:00 | 250 | 3 | | 9 | 2021-02-02 10:45:00 | 200 | 4 | | 12 | 2021-02-02 11:45:00 | 200 | 5 | | 6 | 2021-02-02 09:45:00 | 200 | 6 | | 2 | 2021-02-02 08:30:00 | 200 | 7 | | 7 | 2021-02-02 10:15:00 | 180 | 8 | | 3 | 2021-02-02 08:55:00 | 150 | 9 | | 11 | 2021-02-02 11:30:00 | 150 | 10 | | 4 | 2021-02-02 09:15:00 | 125 | 11 | | 8 | 2021-02-02 10:30:00 | 125 | 12 | +------+---------------------+--------+------+

MYSQL Regular Expressions (REGEXP) with Syntax

 https://www.guru99.com/regular-expressions.html MYSQL Regular Expressions (REGEXP) with Syntax & Examples What are regular expressions? Regular Expressions help search data matching complex criteria. We looked at wildcards in the previous tutorial. If you have worked with wildcards before, you may be asking why learn regular expressions when you can get similar results using the wildcards. Because, compared to wildcards, regular expressions allow us to search data matching even more complex criterion. Basic syntax The basic syntax for a regular expression is as follows SELECT statements... WHERE fieldname REGEXP 'pattern'; HERE – “SELECT statements…” is the standard SELECT statement “WHERE fieldname” is the name of the column on which the regular expression is to be performed on. “REGEXP ‘pattern'” REGEXP is the regular expression operator and ‘pattern’ represents the pattern to be matched by REGEXP. RLIKE is the synonym for R...

Create MySQL Users Accounts and Grant Privileges

https://linuxize.com/post/how-to-create-mysql-user-accounts-and-grant-privileges/ Before you Begin We are assuming that you already have MySQL or MariaDB server installed on your system. All commands are executed inside the MySQL shell as root or administrative user. The minimum  privileges  required to create user accounts and define their privileges is  CREATE USER  and  GRANT . To access the MySQL shell type the following command and enter your MySQL root user password when prompted: mysql -u root -p If you have MySQL version 5.7 or later that uses the  auth_socket  plugin login as root by typing: sudo mysql Create a new MySQL User Account A user account in MySQL consists of two parts: user name and host name. To create a new MySQL user account, run the following command: CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'user_password';   Replace  newuser  with the new user name, and  user_password  with the user password. In...

MySQL: SUBSTRING_INDEX Function

 https://www.techonthenet.com/mysql/functions/substring_index.php MySQL:  SUBSTRING_INDEX Function This MySQL tutorial explains how to use the MySQL  SUBSTRING_INDEX function  with syntax and examples. Description The MySQL SUBSTRING_INDEX function returns the substring of  string  before  number  of occurrences of  delimiter . Syntax The syntax for the SUBSTRING_INDEX function in MySQL is: SUBSTRING_INDEX( string, delimiter, number ) Parameters or Arguments string The source string. delimiter The delimiter to search for in  string . number The number of times to search for  delimiter . Note If  number  is a positive value, everything from the left of the targeted  delimiter  is returned by the SUBSTRING_INDEX function. If  number  is a negative value, everything from the right of the targeted  delimiter  is returned by the SUBSTRING_INDEX function. See also  SUBSTRING function . Applies ...

Menambahkan user baru database mysql dengan "--skip-grant-tables" (Reset Forgotten MySql root Password Under Windows)

 Reset Forgotten MySql root Password Under Windows ========================================================================= Kasus membuat koneksi langsung ke database SAS 1. Stop service MySQL server yang akan ditambahkan usernya (SAS21).     This can be done from Wamp(if you use it), or start “services.msc” using Run window, and stop the service there. 2. Buka cmd 3. Masuk folder bin (sesuaikan dengan kondisi database diinstall)     cd "C:\DBSAS21\bin"     4. Jalankan mysqld.exe -u root --skip-grant-tables    biarkan cmd tsb terbuka 5. Buka cmd lagi 6. Jalankan mysql USE mysql; INSERT INTO `USER` SELECT '%' HOST, 'akk21' USER, PASSWORD('Akk21') Password, Select_priv, Insert_priv, Update_priv,                      Delete_priv, Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv, File_priv, Grant_priv,            ...

Continue after an error “execute failed: Duplicate entry” in MySQL

https://blog-en.openalfa.com/how-to-continue-after-an-error-execute-failed-duplicate-entry-in-mysql When an INSERT statement is executed to add a set of records to a table that has a unique key defined, it may happen that the value of the key in some of the records to be inserted is the same as that of records already in the table. The default behaviour in this case is that the execution fails with an error message “execute failed: Duplicate entry”. When this happens, no record is inserted, not even those whose keys do not clash with the keys of previously existing records. Example: Let’s say we are developing an application that needs a “customers” table, with columns “clientid”,”name” and “email”. There will be a unique key defined on the “clientid” field. We can create the table, and insert the first records successfully: 1 2 3 4 5 6 7 8 9 10 11 12 13 14   mysql > create table customers ( clientid integer , nam...