question
stringlengths
11
28.2k
answer
stringlengths
26
27.7k
tag
stringclasses
130 values
question_id
int64
935
78.4M
score
int64
10
5.49k
I hope there's someone who can help me suggest a suitable data model to be implemented using nosql database Apache Cassandra. More of than I need it to work under high loads and large amounts of data. Simplified I have 3 types of objects: Product Tag ProductTag Product: key - string key name - string .... - some othe...
Something like this: Products : { // Column Family productA : { //Row key name: 'The name of the product' // column price: 33.55 // column tags : 'fun, toy' // column } } ProductTag : { // Column Family fun : { //Row key timeuuid_1 : productA // column timeuu...
Cassandra
2,479,589
10
I'm evaluating a storage platform for an upcoming project and keep coming back to Cassandra. For this project loosing any amount of data is unacceptable. So far we've used a relational database (Microsoft SQL Server), but the data is so varied and large that it has become an issue to store and query. Is Cassandra robus...
Anecdotally: yes, Twitter, Digg, Ooyala, SimpleGeo, Mahalo, and others are using or moving to Cassandra for a primary data store (http://n2.nabble.com/Cassandra-users-survey-td4040068.html). Technically: yes; besides supporting replication (including to multiple datacenters), each Cassandra node has an fsync'd commit l...
Cassandra
1,849,204
10
From the MySQL console, what command displays the schema of any given table?
For formatted output: describe [db_name.]table_name; For an SQL statement that can be used to create a table: show create table [db_name.]table_name;
MySQL
1,498,777
467
I would like to know the following: how to get data from multiple tables in my database? what types of methods are there to do this? what are joins and unions and how are they different from one another? When should I use each one compared to the others? I am planning to use this in my (for example - PHP) applicatio...
Part 1 - Joins and Unions This answer covers: Part 1 Joining two or more tables using an inner join (See the wikipedia entry for additional info) How to use a union query Left and Right Outer Joins (this stackOverflow answer is excellent to describe types of joins) Intersect queries (and how to reproduce them if you...
MySQL
12,475,850
466
I'm trying to use a select statement to get all of the columns from a certain MySQL table except one. Is there a simple way to do this? EDIT: There are 53 columns in this table (NOT MY DESIGN)
Actually there is a way, you need to have permissions of course for doing this ... SET @sql = CONCAT('SELECT ', (SELECT REPLACE(GROUP_CONCAT(COLUMN_NAME), '<columns_to_omit>,', '') FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '<table>' AND TABLE_SCHEMA = '<database>'), ' FROM <table>'); PREPARE stmt1 FROM @sql; ...
MySQL
9,122
466
I am having a big problem trying to connect to mysql. When I run: /usr/local/mysql/bin/mysql start I have the following error : Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (38) I do have mysql.sock under the /var/mysql directory. In /etc/my.cnf I have: [client] port=3306 socket=/var/mys...
If your file my.cnf (usually in the /etc/mysql/ folder) is correctly configured with: socket=/var/lib/mysql/mysql.sock You can check if mysql is running with the following command: mysqladmin -u root -p status Try changing your permission to mysql folder. If you are working locally, you can try: sudo chmod -R 755 /va...
MySQL
5,376,427
463
I believe that I've successfully deployed my (very basic) site to fortrabbit, but as soon as I connect to SSH to run some commands (such as php artisan migrate or php artisan db:seed) I get an error message: [PDOException] SQLSTATE[HY000] [2002] No such file or directory At some point the migration must have worked, b...
One of simplest reasons for this error is that a MySQL server is not running. So verify that first. In case it's up, proceed to other recommendations: Laravel 4: Change "host" in the app/config/database.php file from "localhost" to "127.0.0.1" Laravel 5+: Change "DB_HOST" in the .env file from "localhost" to "127.0.0....
MySQL
20,723,803
460
Basically the question is how to get from this: foo_id foo_name 1 A 1 B 2 C to this: foo_id foo_name 1 A B 2 C
SELECT id, GROUP_CONCAT(name SEPARATOR ' ') FROM table GROUP BY id; https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html#function_group-concat From the link above, GROUP_CONCAT: This function returns a string result with the concatenated non-NULL values from a group. It returns NULL if there are no non-NUL...
MySQL
149,772
457
I have a simple mysql table: CREATE TABLE IF NOT EXISTS `pers` ( `persID` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(35) NOT NULL, `gehalt` int(11) NOT NULL, `chefID` int(11) DEFAULT NULL, PRIMARY KEY (`persID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; INSERT INTO `pers` (`persID`, `na...
The problem is that MySQL, for whatever inane reason, doesn't allow you to write queries like this: UPDATE myTable SET myTable.A = ( SELECT B FROM myTable INNER JOIN ... ) That is, if you're doing an UPDATE/INSERT/DELETE on a table, you can't reference that table in an inner query (you can however referenc...
MySQL
4,429,319
454
I am trying to execute the following query: INSERT INTO table_listnames (name, address, tele) VALUES ('Rupert', 'Somewhere', '022') WHERE NOT EXISTS ( SELECT name FROM table_listnames WHERE name='value' ); But this returns an error. Basically I don't want to insert a record if the 'name' field of the record alread...
I'm not actually suggesting that you do this, as the UNIQUE index as suggested by Piskvor and others is a far better way to do it, but you can actually do what you were attempting: CREATE TABLE `table_listnames` ( `id` int(11) NOT NULL auto_increment, `name` varchar(255) NOT NULL, `address` varchar(255) NOT NULL,...
MySQL
3,164,505
452
I know that you can insert multiple rows at once, is there a way to update multiple rows at once (as in, in one query) in MySQL? Edit: For example I have the following Name id Col1 Col2 Row1 1 6 1 Row2 2 2 3 Row3 3 9 5 Row4 4 16 8 I want to combine all the following Updates into ...
Yes, that's possible - you can use INSERT ... ON DUPLICATE KEY UPDATE. Using your example: INSERT INTO table (id,Col1,Col2) VALUES (1,1,1),(2,2,3),(3,9,3),(4,10,12) ON DUPLICATE KEY UPDATE Col1=VALUES(Col1),Col2=VALUES(Col2);
MySQL
3,432
450
I'm running the following MySQL UPDATE statement: mysql> update customer set account_import_id = 1; ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction I'm not using a transaction, so why would I be getting this error? I even tried restarting my MySQL server and it didn't help. The table has 406...
HOW TO FORCE UNLOCK for locked tables in MySQL: Breaking locks like this may cause atomicity in the database to not be enforced on the sql statements that caused the lock. This is hackish, and the proper solution is to fix your application that caused the locks. However, when dollars are on the line, a swift kick will ...
MySQL
5,836,623
449
Is there a way to get the count of rows in all tables in a MySQL database without running a SELECT count() on each table?
SELECT SUM(TABLE_ROWS) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '{your_db}'; Note from the docs though: For InnoDB tables, the row count is only a rough estimate used in SQL optimization. You'll need to use COUNT(*) for exact counts (which is more expensive).
MySQL
286,039
449
I have installed MySQL Community Edition 5.5 on my local machine and I want to allow remote connections so that I can connect from external source. How can I do that?
That is allowed by default on MySQL. What is disabled by default is remote root access. If you want to enable that, run this SQL command locally: GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; FLUSH PRIVILEGES; And then find the following line and comment it out in your my.cnf...
MySQL
14,779,104
448
I have a table with the following columns in a MySQL database [id, url] And the URLs are like: http://domain1.example/images/img1.jpg I want to update all the URLs to another domain http://domain2.example/otherfolder/img1.jpg keeping the name of the file as is. What's the query must I run?
UPDATE urls SET url = REPLACE(url, 'domain1.example/images/', 'domain2.example/otherfolder/')
MySQL
10,177,208
447
I have a table with the following fields: id (Unique) url (Unique) title company site_id Now, I need to remove rows having same title, company and site_id. One way to do it will be using the following SQL along with a script (PHP): SELECT title, site_id, location, id, count( * ) FROM jobs GROUP BY site_id, company, ...
A really easy way to do this is to add a UNIQUE index on the 3 columns. When you write the ALTER statement, include the IGNORE keyword. Like so: ALTER IGNORE TABLE jobs ADD UNIQUE INDEX idx_name (site_id, title, company); This will drop all the duplicate rows. As an added benefit, future INSERTs that are duplicates...
MySQL
3,311,903
447
What's the difference between VARCHAR and CHAR in MySQL? I am trying to store MD5 hashes.
VARCHAR is variable-length. CHAR is fixed length. If your content is a fixed size, you'll get better performance with CHAR. See the MySQL page on CHAR and VARCHAR Types for a detailed explanation (be sure to also read the comments).
MySQL
1,885,630
447
How do I rename a column in table xyz? The columns are: Manufacurerid, name, status, AI, PK, int I want to rename to manufacturerid I tried using PHPMyAdmin panel, but I get this error: MySQL said: Documentation #1025 - Error on rename of '.\shopping\#sql-c98_26' to '.\shopping\tblmanufacturer' (errno: 150)
Lone Ranger is very close... in fact, you also need to specify the datatype of the renamed column. For example: ALTER TABLE `xyz` CHANGE `manufacurerid` `manufacturerid` INT; Remember : Replace INT with whatever your column data type is (REQUIRED) Tilde/ Backtick (`) is optional
MySQL
4,002,340
443
I am really interested in how MySQL indexes work, more specifically, how can they return the data requested without scanning the entire table? It's off-topic, I know, but if there is someone who could explain this to me in detail, I would be very, very thankful.
Basically an index on a table works like an index in a book (that's where the name came from): Let's say you have a book about databases and you want to find some information about, say, storage. Without an index (assuming no other aid, such as a table of contents) you'd have to go through the pages one by one, until ...
MySQL
3,567,981
443
I got the Error Code: 2013. Lost connection to MySQL server during query error when I tried to add an index to a table using MySQL Workbench. I also noticed that it appears whenever I run long query. Is there a way to increase the timeout value?
New versions of MySQL WorkBench have an option to change specific timeouts. For me it was under Edit → Preferences → SQL Editor → DBMS connection read time out (in seconds): 600 Changed the value to 6000. Also unchecked limit rows as putting a limit in every time I want to search the whole data set gets tiresome.
MySQL
10,563,619
442
I'm using MySQL 5.7.13 on my windows PC with WAMP Server. My problem is while executing this query SELECT * FROM `tbl_customer_pod_uploads` WHERE `load_id` = '78' AND `status` = 'Active' GROUP BY `proof_type` I'm getting always error like this. Expression #1 of SELECT list is not in GROUP BY clause and contains...
This Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'returntr_prod.tbl_customer_pod_uploads.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by will be simply solved by changing the sql mode in MySQL by ...
MySQL
41,887,460
440
I looked around some and didn't find what I was after so here goes. SELECT * FROM trees WHERE trees.`title` LIKE '%elm%' This works fine, but not if the tree is named Elm or ELM etc... How do I make SQL case insensitive for this wild-card search? I'm using MySQL 5 and Apache.
I've always solved this using lower: SELECT * FROM trees WHERE LOWER( trees.title ) LIKE '%elm%'
MySQL
2,876,789
440
How can I import a database with mysql from terminal? I cannot find the exact syntax.
Assuming you're on a Linux or Windows console: Prompt for password: mysql -u <username> -p <databasename> < <filename.sql> Enter password directly (not secure): mysql -u <username> -p<PlainPassword> <databasename> < <filename.sql> Example: mysql -u root -p wp_users < wp_users.sql mysql -u root -pPassword123 wp_users...
MySQL
4,546,778
439
I have a database that is quite large so I want to export it using Command Prompt but I don't know how to. I am using WAMP.
First check if your command line recognizes mysql command. If not go to command & type in: set path=c:\wamp\bin\mysql\mysql5.1.36\bin Then use this command to export your database: mysqldump -u YourUser -p YourDatabaseName > wantedsqlfile.sql You will then be prompted for the database password. This exports the datab...
MySQL
3,031,412
435
I want to keep a backup of all my MySQL databases. I have more than 100 MySQL databases. I want to export all of them at the same time and again import all of them into my MySQL server at once. How can I do that?
Export: mysqldump -u root -p --all-databases > alldb.sql Look up the documentation for mysqldump. You may want to use some of the options mentioned in comments: mysqldump -u root -p --opt --all-databases > alldb.sql mysqldump -u root -p --all-databases --skip-lock-tables > alldb.sql Import: mysql -u root -p < alldb.s...
MySQL
9,497,869
433
I have an email column that I want to be unique. But I also want it to accept null values. Can my database have 2 null emails that way?
Yes, MySQL allows multiple NULLs in a column with a unique constraint. CREATE TABLE table1 (x INT NULL UNIQUE); INSERT table1 VALUES (1); INSERT table1 VALUES (1); -- Duplicate entry '1' for key 'x' INSERT table1 VALUES (NULL); INSERT table1 VALUES (NULL); SELECT * FROM table1; Result: x NULL NULL 1 This is not tru...
MySQL
3,712,222
430
I want to add a Foreign Key to a table called "katalog". ALTER TABLE katalog ADD CONSTRAINT `fk_katalog_sprache` FOREIGN KEY (`Sprache`) REFERENCES `Sprache` (`ID`) ON DELETE SET NULL ON UPDATE SET NULL; When I try to do this, I get this error message: Error Code: 1005. Can't create table 'mytable.#sql-7fb1_7d3a' (...
To add a foreign key (grade_id) to an existing table (users), follow the following steps: ALTER TABLE users ADD grade_id SMALLINT UNSIGNED NOT NULL DEFAULT 0; ALTER TABLE users ADD CONSTRAINT fk_grade_id FOREIGN KEY (grade_id) REFERENCES grades(id);
MySQL
10,028,214
428
I need to store a url in a MySQL table. What's the best practice for defining a field that will hold a URL with an undetermined length?
Lowest common denominator max URL length among popular web browsers: 2,083 (Internet Explorer) http://dev.mysql.com/doc/refman/5.0/en/char.html Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later version...
MySQL
219,569
426
Is there a way to grab the columns name of a table in MySQL using PHP?
You can use DESCRIBE: DESCRIBE my_table; Or in newer versions you can use INFORMATION_SCHEMA: SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'my_database' AND TABLE_NAME = 'my_table'; Or you can use SHOW COLUMNS: SHOW COLUMNS FROM my_table; Or to get column names with comma in a line: SE...
MySQL
1,526,688
424
What is the difference between tinyint, smallint, mediumint, bigint and int in MySQL? In what cases should these be used?
They take up different amounts of space and they have different ranges of acceptable values. Here are the sizes and ranges of values for SQL Server, other RDBMSes have similar documentation: MySQL Postgres Oracle (they just have a NUMBER datatype really) DB2 Turns out they all use the same specification (with a few m...
MySQL
2,991,405
423
I seem to be unable to re-create a simple user I've deleted, even as root in MySQL. My case: user 'jack' existed before, but I deleted it from mysql.user in order to recreate it. I see no vestiges of this in that table. If I execute this command for some other, random username, say 'jimmy', it works fine (just as it or...
yes this bug is there. However, I found a small workaround. Assume the user is there, so drop the user After deleting the user, there is need to flush the mysql privileges Now create the user. That should solve it. Assuming we want to create the user admin @ localhost, these would be the commands: drop user admin@lo...
MySQL
5,555,328
422
I'm trying to find out if a row exists in a table. Using MySQL, is it better to do a query like this: SELECT COUNT(*) AS total FROM table1 WHERE ... and check to see if the total is non-zero or is it better to do a query like this: SELECT * FROM table1 WHERE ... LIMIT 1 and check to see if any rows were returned? In ...
You could also try EXISTS: SELECT EXISTS(SELECT * FROM table1 WHERE ...) and per the documentation, you can SELECT anything. Traditionally, an EXISTS subquery starts with SELECT *, but it could begin with SELECT 5 or SELECT column1 or anything at all. MySQL ignores the SELECT list in such a subquery, so it makes ...
MySQL
1,676,551
422
Let's say I am doing a MySQL INSERT into one of my tables and the table has the column item_id which is set to autoincrement and primary key. How do I get the query to output the value of the newly generated primary key item_id in the same query? Currently I am running a second query to retrieve the id but this hardly ...
You need to use the LAST_INSERT_ID() function: http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_last-insert-id Eg: INSERT INTO table_name (col1, col2,...) VALUES ('val1', 'val2'...); SELECT LAST_INSERT_ID(); This will get you back the PRIMARY KEY value of the last row that you inserted: The ...
MySQL
17,112,852
418
I've been trying to figure out how I can make a query with MySQL that checks if the value (string $haystack ) in a certain column contains certain data (string $needle), like this: SELECT * FROM `table` WHERE `column`.contains('{$needle}') In PHP, the function is called substr($haystack, $needle), so maybe: WHERE subs...
Quite simple actually: SELECT * FROM `table` WHERE `column` LIKE '%{$needle}%' The % is a wildcard for any characters set (none, one or many). Do note that this can get slow on very large datasets so if your database grows you'll need to use fulltext indices.
MySQL
2,602,252
417
I'm trying to setup up MySQL on mac os 10.6 using Homebrew by brew install mysql 5.1.52. Everything goes well and I am also successful with the mysql_install_db. However when I try to connect to the server using: /usr/local/Cellar/mysql/5.1.52/bin/mysqladmin -u root password 'mypass' I get: /usr/local/Cellar/mysql/5...
I think one can end up in this position with older versions of mysql already installed. I had the same problem and none of the above solutions worked for me. I fixed it thus: Used brew's remove & cleanup commands, unloaded the launchctl script, then deleted the mysql directory in /usr/local/var, deleted my existing /et...
MySQL
4,359,131
416
What is the correct format to pass to the date() function in PHP if I want to insert the result into a MySQL datetime type column? I've been trying date('Y-M-D G:i:s') but that just inserts "0000-00-00 00:00:00" everytime.
The problem is that you're using 'M' and 'D', which are a textual representations, MySQL is expecting a numeric representation of the format 2010-02-06 19:30:13 Try: date('Y-m-d H:i:s') which uses the numeric equivalents. edit: switched G to H, though it may not have impact, you probably want to use 24-hour format with...
MySQL
2,215,354
413
I have a function that returns five characters with mixed case. If I do a query on this string it will return the value regardless of case. How can I make MySQL string queries case sensitive?
Use this to make a case-sensitive query: SELECT * FROM `table` WHERE BINARY `column` = 'value'
MySQL
5,629,111
412
I have just installed Debian Lenny with Apache, MySQL, and PHP and I am receiving a PDOException could not find driver. This is the specific line of code it is referring to: $dbh = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASS) DB_HOST, DB_NAME, DB_USER, and DB_PASS are constants that I have ...
You need to have a module called pdo_mysql. Looking for following in phpinfo(), pdo_mysql PDO Driver for MySQL, client library version => 5.1.44
MySQL
2,852,748
407
I am having a problem with BLOB fields in my MySQL database - when uploading files larger than approx 1MB I get an error Packets larger than max_allowed_packet are not allowed. Here is what i've tried: In MySQL Query Browser I ran a show variables like 'max_allowed_packet' which gave me 1048576. Then I execute the que...
Change in the my.ini or ~/.my.cnf file by including the single line under [mysqld] or [client] section in your file: max_allowed_packet=500M then restart the MySQL service and you are done. See the documentation for further information.
MySQL
8,062,496
406
I've got the following two tables (in MySQL): Phone_book +----+------+--------------+ | id | name | phone_number | +----+------+--------------+ | 1 | John | 111111111111 | +----+------+--------------+ | 2 | Jane | 222222222222 | +----+------+--------------+ Call +----+------+--------------+ | id | date | phone_numbe...
There's several different ways of doing this, with varying efficiency, depending on how good your query optimiser is, and the relative size of your two tables: This is the shortest statement, and may be quickest if your phone book is very short: SELECT * FROM Call WHERE phone_number NOT IN (SELECT phone_number FR...
MySQL
367,863
405
Someone sent me a SQL query where the GROUP BY clause consisted of the statement: GROUP BY 1. This must be a typo right? No column is given the alias 1. What could this mean? Am I right to assume that this must be a typo?
It means to group by the first column of your result set regardless of what it's called. You can do the same with ORDER BY.
MySQL
7,392,730
401
I am trying to forward engineer my new schema onto my database server, but I can't figure out why I am getting this error. I've tried to search for the answer here, but everything I've found has said to either set the database engine to InnoDB or to make sure the keys I'm trying to use as a foreign key are primary keys...
I'm guessing that Clients.Case_Number and/or Staff.Emp_ID are not exactly the same data type as Clients_has_Staff.Clients_Case_Number and Clients_has_Staff.Staff_Emp_ID. Perhaps the columns in the parent tables are INT UNSIGNED? They need to be exactly the same data type in both tables.
MySQL
16,969,060
400
How do you select all the columns from one table and just some columns from another table using JOIN? In MySQL.
Just use the table name: SELECT myTable.*, otherTable.foo, otherTable.bar... That would select all columns from myTable and columns foo and bar from otherTable.
MySQL
3,492,904
397
How do I set the initial value for an "id" column in a MySQL table that start from 1001? I want to do an insert "INSERT INTO users (name, email) VALUES ('{$name}', '{$email}')"; Without specifying the initial value for the id column.
Use this: ALTER TABLE users AUTO_INCREMENT=1001; or if you haven't already added an id column, also add it ALTER TABLE users ADD id INT UNSIGNED NOT NULL AUTO_INCREMENT, ADD INDEX (id);
MySQL
1,485,668
394
My Current Data for SELECT PROD_CODE FROM `PRODUCT` is PROD_CODE 2 5 7 8 22 10 9 11 I have tried all the four queries and none work. (Ref) SELECT CAST(PROD_CODE) AS INT FROM PRODUCT; SELECT CAST(PROD_CODE AS INT) FROM PRODUCT; SELECT CAST(PROD_CODE) AS INTEGER FROM PRODUCT; SELECT CAST(PROD_CODE AS INTEGER) FROM P...
As described in Cast Functions and Operators: The type for the result can be one of the following values: BINARY[(N)] CHAR[(N)] DATE DATETIME DECIMAL[(M[,D])] SIGNED [INTEGER] TIME UNSIGNED [INTEGER] Therefore, you should use: SELECT CAST(PROD_CODE AS UNSIGNED) FROM PRODUCT
MySQL
12,126,991
393
I have changed all the php.ini parameters I know: upload_max_filesize, post_max_size. Why am I still seeing 2MB? Im using Zend Server CE, on a Ubuntu VirtualBox over a Windows 7 host.
Find the file called: php.ini on your server and follow below steps With apache2 and php5 installed you need to make three changes in the php.ini file. First open the file for editing, e.g.: sudo gedit /etc/php5/apache2/php.ini OR sudo gedit /etc/php/7.0/apache2/php.ini Next, search for the post_max_size entry, and en...
MySQL
3,958,615
391
When I tried running the following command on MySQL from within Terminal: mysql -u $user -p$password -e "statement" The execution works as expected, but it always issues a warning: Warning: Using a password on the command line interface can be insecure. However, I have to conduct the statement above using an enviro...
I use something like: mysql --defaults-extra-file=/path/to/config.cnf or mysqldump --defaults-extra-file=/path/to/config.cnf Where config.cnf contains: [client] user = "whatever" password = "whatever" host = "whatever" This allows you to have multiple config files - for different servers/roles/databases. Using ~/.m...
MySQL
20,751,352
390
If I have a MySQL table looking something like this: company_name action pagecount Company A PRINT 3 Company A PRINT 2 Company A PRINT 3 Company B EMAIL Company B PRINT 2 Company B PRINT 2 Company B PRINT 1 Company A PRINT 3 Is it possible to run a MySQL query to get output like this: compan...
This basically is a pivot table. A nice tutorial on how to achieve this can be found here: http://www.artfulsoftware.com/infotree/qrytip.php?id=78 I advise reading this post and adapt this solution to your needs. Update After the link above is currently not available any longer I feel obliged to provide some additional...
MySQL
7,674,786
388
I am looking for the syntax for dumping all data in my mysql database. I don't want any table information.
mysqldump --no-create-info ... Also you may use: --skip-triggers: if you are using triggers --no-create-db: if you are using --databases ... option --compact: if you want to get rid of extra comments
MySQL
5,109,993
388
I have a innoDB table which records online users. It gets updated on every page refresh by a user to keep track of which pages they are on and their last access date to the site. I then have a cron that runs every 15 minutes to DELETE old records. I got a 'Deadlock found when trying to get lock; try restarting transact...
One easy trick that can help with most deadlocks is sorting the operations in a specific order. You get a deadlock when two transactions are trying to lock two locks at opposite orders, ie: connection 1: locks key(1), locks key(2); connection 2: locks key(2), locks key(1); If both run at the same time, connection 1 w...
MySQL
2,332,768
388
Is there a difference between a schema and a database in MySQL? In SQL Server, a database is a higher level container in relation to a schema. I read that Create Schema and Create Database do essentially the same thing in MySQL, which leads me to believe that schemas and databases are different words for the same obje...
As defined in the MySQL Glossary: In MySQL, physically, a schema is synonymous with a database. You can substitute the keyword SCHEMA instead of DATABASE in MySQL SQL syntax, for example using CREATE SCHEMA instead of CREATE DATABASE. Some other database products draw a distinction. For example, in the Oracle Database...
MySQL
11,618,277
387
How do I get the current AUTO_INCREMENT value for a table in MySQL?
You can get all of the table data by using this query: SHOW TABLE STATUS FROM `DatabaseName` WHERE `name` LIKE 'TableName' ; You can get exactly this information by using this query: SELECT `AUTO_INCREMENT` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'DatabaseName' AND TABLE_NAME = 'TableName';
MySQL
15,821,532
385
I am moving away from Linode because I don't have the Linux sysadmin skills necessary; before I complete the transition to a more noob-friendly service, I need to export the contents of a MySQL database. Is there a way I can do this from the command line?
You can accomplish this using the mysqldump command-line function. For example: If it's an entire DB, then: $ mysqldump -u [uname] -p db_name > db_backup.sql If it's all DBs, then: $ mysqldump -u [uname] -p --all-databases > all_db_backup.sql If it's specific tables within a DB, then: $ mysqldump -u [uname] ...
MySQL
13,484,667
385
I've just started getting into Node.js. I come from a PHP background, so I'm fairly used to using MySQL for all my database needs. How can I use MySQL with Node.js?
Check out the node.js module list node-mysql — A node.js module implementing the MySQL protocol node-mysql2 — Yet another pure JS async driver. Pipelining, prepared statements. node-mysql-libmysqlclient — MySQL asynchronous bindings based on libmysqlclient node-mysql looks simple enough: var mysql = require('mys...
MySQL
5,818,312
384
How can you connect to MySQL from the command line in a Mac? (i.e. show me the code) I'm doing a PHP/SQL tutorial, but it starts by assuming you're already in MySQL.
See here http://dev.mysql.com/doc/refman/5.0/en/connecting.html mysql -u USERNAME -pPASSWORD -h HOSTNAMEORIP DATABASENAME The options above means: -u: username -p: password (**no space between -p and the password text**) -h: host last one is name of the database that you wanted to connect. Look into the link, it's ...
MySQL
5,131,931
384
When I issue SHOW PROCESSLIST query, only the first 100 characters of the running SQL query are returned in the info column. Is it possible to change MySQL config or issue a different kind of request to see complete query (the queries I'm looking at are longer than 100 characters)
SHOW FULL PROCESSLIST If you don't use FULL, "only the first 100 characters of each statement are shown in the Info field". When using phpMyAdmin, you should also click on the "Full texts" option ("← T →" on top left corner of a results table) to see untruncated results.
MySQL
3,638,689
383
I have been very excited about MongoDb and have been testing it lately. I had a table called posts in MySQL with about 20 million records indexed only on a field called 'id'. I wanted to compare speed with MongoDB and I ran a test which would get and print 15 records randomly from our huge databases. I ran the query ab...
MongoDB is not magically faster. If you store the same data, organised in basically the same fashion, and access it exactly the same way, then you really shouldn't expect your results to be wildly different. After all, MySQL and MongoDB are both GPL, so if Mongo had some magically better IO code in it, then the MySQL t...
MySQL
9,702,643
382
I'm using PuTTY to run: mysql> SELECT * FROM sometable; sometable has many fields and this results in many columns trying to be displayed in the terminal. The fields wrap onto the next line so it is very hard to line up column titles with field values. What solutions are there for viewing such data in terminal? I don'...
Terminate the query with \G in place of ;. For example: SELECT * FROM sometable\G This query displays the rows vertically, like this: *************************** 1. row *************************** Host: localhost Db: mydatabase1 User: myuser1 Select_priv:...
MySQL
924,729
380
I have an unnormalized events-diary CSV from a client that I'm trying to load into a MySQL table so that I can refactor into a sane format. I created a table called 'CSVImport' that has one field for every column of the CSV file. The CSV contains 99 columns , so this was a hard enough task in itself: CREATE TABLE 'CSVI...
Use mysqlimport to load a table into the database: mysqlimport --ignore-lines=1 \ --fields-terminated-by=, \ --local -u root \ -p Database \ TableName.csv I found it at http://chriseiffel.com/everything-linux/how-to-import-a-large-csv-file-to-mysql/ To make the delimite...
MySQL
3,635,166
379
I need to get UTF-8 working in my Java webapp (servlets + JSP, no framework used) to support äöå etc. for regular Finnish text and Cyrillic alphabets like ЦжФ for special cases. My setup is the following: Development environment: Windows XP Production environment: Debian Database used: MySQL 5.x Users mainly use Fire...
Answering myself as the FAQ of this site encourages it. This works for me: Mostly characters äåö are not a problematic as the default character set used by browsers and tomcat/java for webapps is latin1 ie. ISO-8859-1 which "understands" those characters. To get UTF-8 working under Java+Tomcat+Linux/Windows+Mysql requ...
MySQL
138,948
374
I want to store a hashed password (using BCrypt) in a database. What would be a good type for this, and which would be the correct length? Are passwords hashed with BCrypt always of same length? EDIT Example hash: $2a$10$KssILxWNR6k62B7yiX0GAe2Q7wwHlrzhF3LqtVvpyvHZf0MwvNfVu After hashing some passwords, it seems that B...
The modular crypt format for bcrypt consists of $2$, $2a$ or $2y$ identifying the hashing algorithm and format a two digit value denoting the cost parameter, followed by $ a 53 characters long base-64-encoded value (they use the alphabet ., /, 0–9, A–Z, a–z that is different to the standard Base 64 Encoding alphabet) ...
MySQL
5,881,169
373
How do you connect to a MySQL database in Java? When I try, I get java.sql.SQLException: No suitable driver found for jdbc:mysql://database/table at java.sql.DriverManager.getConnection(DriverManager.java:689) at java.sql.DriverManager.getConnection(DriverManager.java:247) Or java.lang.ClassNotFoundException...
Here's a step by step explanation how to install MySQL and JDBC and how to use it: Download and install the MySQL server. Just do it the usual way. Remember the port number whenever you've changed it. It's by default 3306. Download the JDBC driver and put in classpath, extract the ZIP file and put the containing JAR ...
MySQL
2,839,321
372
I have a column in a table which might contain null or empty values. How do I check if a column is empty or null in the rows present in a table? (e.g. null or '' or ' ' or ' ' and ...)
This will select all rows where some_col is NULL or '' (empty string) SELECT * FROM table WHERE some_col IS NULL OR some_col = '';
MySQL
8,470,813
369
I'd like to get all of a mysql table's col names into an array in php? Is there a query for this?
The best way is to use the INFORMATION_SCHEMA metadata virtual database. Specifically the INFORMATION_SCHEMA.COLUMNS table... SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA`='yourdatabasename' AND `TABLE_NAME`='yourtablename'; It's VERY powerful, and can give you TONS of informati...
MySQL
4,165,195
368
I'm currently developing an application using a MySQL database. The database-structure is still in flux and changes while development progresses (I change my local copy, leaving the one on the test-server alone). Is there a way to compare the two instances of the database to see if there were any changes? While current...
If you're working with small databases I've found running mysqldump on both databases with the --skip-comments and --skip-extended-insert options to generate SQL scripts, then running diff on the SQL scripts works pretty well. By skipping comments you avoid meaningless differences such as the time you ran the mysqldump...
MySQL
225,772
368
I get this error when I try to source a large SQL file (a big INSERT query). mysql> source file.sql ERROR 2006 (HY000): MySQL server has gone away No connection. Trying to reconnect... Connection id: 2 Current database: *** NONE *** ERROR 2006 (HY000): MySQL server has gone away No connection. Trying to reconnect....
max_allowed_packet=64M Adding this line into my.cnf file solves my problem. This is useful when the columns have large values, which cause the issues, you can find the explanation here. On Windows this file is located at: "C:\ProgramData\MySQL\MySQL Server 5.6" On Linux (Ubuntu): /etc/mysql
MySQL
10,474,922
366
I want to combine multiple databases in my system. Most of the time the database is MySQL; but it may differ in future i.e. Admin can generate such a reports which is use source of heterogeneous database system. So my question is does Laravel provide any Facade to deal with such situations? Or any other framework have...
From Laravel Docs: You may access each connection via the connection method on the DB facade when using multiple connections. The name passed to the connection method should correspond to one of the connections listed in your config/database.php configuration file: $users = DB::connection('foo')->select(...); Define C...
MySQL
31,847,054
365
In MySQL, I know I can list the tables in a database with: SHOW TABLES However, I want to insert these table names into another table, for instance: INSERT INTO metadata(table_name) SHOW TABLES /* does not work */ Is there a way to get the table names using a standard SELECT statement, something like: INSERT INTO met...
To get the name of all tables use: SELECT table_name FROM information_schema.tables; To get the name of the tables from a specific database use: SELECT table_name FROM information_schema.tables WHERE table_schema = 'your_database_name'; Now, to answer the original question, use this query: INSERT INTO table_name ...
MySQL
8,334,493
365
I want to store many records in a MySQL database. All of them contains money values. But I don't know how many digits will be inserted for each one. Which data type do I have to use for this purpose? VARCHAR or INT (or other numeric data types)?
Since money needs an exact representation don't use data types that are only approximate like float. You can use a fixed-point numeric data type for that like decimal(15,2) 15 is the precision (total length of value including decimal places) 2 is the number of digits after decimal point The max possible number in thi...
MySQL
13,030,368
363
I am using Fedora 14 and I have MySQL and MySQL server 5.1.42 installed and running. Now I tried to do this as root user: gem install mysql But I get this error: Building native extensions. This could take a while... ERROR: Error installing mysql: ERROR: Failed to build gem native extension. /usr/bin/ruby extco...
For those who may be confused by the accepted answer, as I was, you also need to have the ruby headers installed [ruby-devel]. The article that saved my hide is here. And this is the revised solution (note that I'm on Fedora 13): yum -y install gcc mysql-devel ruby-devel rubygems gem install -y mysql -- --with-mysql-co...
MySQL
4,304,438
363
Is it possible for me to turn on audit logging on my mysql database? I basically want to monitor all queries for an hour, and dump the log to a file.
Besides what I came across here, running the following was the simplest way to dump queries to a log file without restarting SET global log_output = 'FILE'; SET global general_log_file='/Applications/MAMP/logs/mysql_general.log'; SET global general_log = 1; can be turned off with SET global general_log = 0;
MySQL
303,994
363
So I'm trying to add Foreign Key constraints to my database as a project requirement and it worked the first time or two on different tables, but I have two tables on which I get an error when trying to add the Foreign Key Constraints. The error message that I get is: ERROR 1215 (HY000): Cannot add foreign key constr...
To find the specific error run this: SHOW ENGINE INNODB STATUS; And look in the LATEST FOREIGN KEY ERROR section. The data type for the child column must match the parent column exactly. For example, since medicalhistory.MedicalHistoryID is an INT, Patient.MedicalHistory also needs to be an INT, not a SMALLINT. Also, ...
MySQL
15,534,977
362
In a MySQL JOIN, what is the difference between ON and USING()? As far as I can tell, USING() is just more convenient syntax, whereas ON allows a little more flexibility when the column names are not identical. However, that difference is so minor, you'd think they'd just do away with USING(). Is there more to this tha...
It is mostly syntactic sugar, but a couple differences are noteworthy: ON is the more general of the two. One can join tables ON a column, a set of columns and even a condition. For example: SELECT * FROM world.City JOIN world.Country ON (City.CountryCode = Country.Code) WHERE ... USING is useful when both tables shar...
MySQL
11,366,006
362
I want to search in all fields from all tables of a MySQL database a given string, possibly using syntax as: SELECT * FROM * WHERE * LIKE '%stuff%' Is it possible to do something like this?
You could do an SQLDump of the database (and its data) then search that file.
MySQL
639,531
362
I have a table which has several ID columns to other tables. I want a foreign key to force integrity only if I put data in there. If I do an update at a later time to populate that column, then it should also check the constraint. (This is likely database server dependant, I'm using MySQL & InnoDB table type) I believe...
Yes, you can enforce the constraint only when the value is not NULL. This can be easily tested with the following example: CREATE DATABASE t; USE t; CREATE TABLE parent (id INT NOT NULL, PRIMARY KEY (id) ) ENGINE=INNODB; CREATE TABLE child (id INT NULL, parent_id INT NULL, ...
MySQL
2,366,854
361
SELECT * FROM table ORDER BY string_length(column); Is there a MySQL function to do this (of course instead of string_length)?
You are looking for CHAR_LENGTH() to get the number of characters in a string. For multi-byte charsets LENGTH() will give you the number of bytes the string occupies, while CHAR_LENGTH() will return the number of characters.
MySQL
1,870,937
360
I'm tired of opening Dia and creating a database diagram at the beginning of every project. Is there a tool out there that will let me select specific tables and then create a database diagram for me based on a MySQL database? Preferably it would allow me to edit the diagram afterward since none of the foreign keys are...
Try MySQL Workbench, formerly DBDesigner 4: http://dev.mysql.com/workbench/ This has a "Reverse Engineer Database" mode: Database -> Reverse Engineer
MySQL
2,488
360
Every time is set up a new SQL table or add a new varchar column to an existing table, I am wondering one thing: what is the best value for the length. So, lets say, you have a column called name of type varchar. So, you have to choose the length. I cannot think of a name > 20 chars, but you will never know. But inste...
No DBMS I know of has any "optimization" that will make a VARCHAR with a 2^n length perform better than one with a max length that is not a power of 2. I think early SQL Server versions actually treated a VARCHAR with length 255 differently than one with a higher maximum length. I don't know if this is still the case. ...
MySQL
8,295,131
359
How do you get the rows that contain the max value for each grouped set? I've seen some overly-complicated variations on this question, and none with a good answer. I've tried to put together the simplest possible example: Given a table like that below, with person, group, and age columns, how would you get the oldest...
The correct solution is: SELECT o.* FROM `Persons` o # 'o' from 'oldest person in group' LEFT JOIN `Persons` b # 'b' from 'bigger age' ON o.Group = b.Group AND o.Age < b.Age WHERE b.Age is NULL # bigger age not found How it works: It matches each row from o with a...
MySQL
12,102,200
358
I tried but failed: mysql> select max(1,0); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0)' at line 1
Use GREATEST() E.g.: SELECT GREATEST(2,1); Note: Whenever if any single value contains null at that time this function always returns null (Thanks to user @sanghavi7)
MySQL
1,565,688
356
Is it possible to check if a (MySQL) database exists after having made a connection. I know how to check if a table exists in a DB, but I need to check if the DB exists. If not I have to call another piece of code to create it and populate it. I know this all sounds somewhat inelegant - this is a quick and dirty app.
SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'DBName' If you just need to know if a db exists so you won't get an error when you try to create it, simply use (From here): CREATE DATABASE IF NOT EXISTS DBName;
MySQL
838,978
355
I have a query that inserts using a SELECT statement: INSERT INTO courses (name, location, gid) SELECT name, location, gid FROM courses WHERE cid = $cid Is it possible to only select "name, location" for the insert, and set gid to something else in the query?
Yes, absolutely, but check your syntax. INSERT INTO courses (name, location, gid) SELECT name, location, 1 FROM courses WHERE cid = 2 You can put a constant of the same type as gid in its place, not just 1, of course. And, I just made up the cid value.
MySQL
5,391,344
352
My current query looks like this: SELECT * FROM fiberbox f WHERE f.fiberBox LIKE '%1740 %' OR f.fiberBox LIKE '%1938 %' OR f.fiberBox LIKE '%1940 %' I did some looking around and can't find anything similar to a LIKE IN() - I envision it working like this: SELECT * FROM fiberbox f WHERE f.fiberbox LIKE IN('%140 %', '%...
A REGEXP might be more efficient, but you'd have to benchmark it to be sure, e.g. SELECT * from fiberbox where field REGEXP '1740|1938|1940';
MySQL
1,127,088
352
I'm setting up a database using phpMyAdmin. I have two tables (foo and bar), indexed on their primary keys. I am trying to create a relational table (foo_bar) between them, using their primary keys as foreign keys. I created these tables as MyISAM, but have since changed all three to InnoDB, because I read that MyISAM ...
If you want to use phpMyAdmin to set up relations, you have to do 2 things. First of all, you have to define an index on the foreign key column in the referring table (so foo_bar.foo_id, in your case). Then, go to relation view (in the referring table) and select the referred column (so in your case foo.id) and the on ...
MySQL
459,312
352
Is the database query faster if I insert multiple rows at once: like INSERT.... UNION INSERT.... UNION (I need to insert like 2-3000 rows)
INSERT statements that use VALUES syntax can insert multiple rows. To do this, include multiple lists of column values, each enclosed within parentheses and separated by commas. Example: INSERT INTO tbl_name (a,b,c) VALUES (1,2,3), (4,5,6), (7,8,9); Source
MySQL
6,889,065
349
What is the difference between MUL, PRI and UNI in MySQL? I'm working on a MySQL query, using the command: desc mytable; One of the fields is shown as being a MUL key, others show up as UNI or PRI. I know that if a key is PRI, only one record per table can be associated with that key. If a key is MUL, does that mean ...
DESCRIBE <table>; This is acutally a shortcut for: SHOW COLUMNS FROM <table>; In any case, there are three possible values for the "Key" attribute: PRI UNI MUL The meaning of PRI and UNI are quite clear: PRI => primary key UNI => unique key The third possibility, MUL, (which you asked about) is basically an inde...
MySQL
5,317,889
349
I'm using GROUP_CONCAT() in a MySQL query to convert multiple rows into a single string. However, the maximum length of the result of this function is 1024 characters. I'm very well aware that I can change the param group_concat_max_len to increase this limit: SET SESSION group_concat_max_len = 1000000; However, on th...
SET SESSION group_concat_max_len = 1000000; is a temporary, session-scope, setting. It only applies to the current session You should use it like this. SET SESSION group_concat_max_len = 1000000; select group_concat(column) from table group by column You can do this even in sharing hosting, but when you use an other...
MySQL
2,567,000
349
I have been reading about scalable architectures recently. In that context, two words that keep on showing up with regards to databases are sharding and partitioning. I looked up descriptions but still ended up confused. Could the experts at stackoverflow help me get the basics right? What is the difference between sh...
Partitioning is more a generic term for dividing data across tables or databases. Sharding is one specific type of partitioning, part of what is called horizontal partitioning. Here you replicate the schema across (typically) multiple instances or servers, using some kind of logic or identifier to know which instance o...
MySQL
20,771,435
348
Currently I am doing a very basic OrderBy in my statement. SELECT * FROM tablename WHERE visible=1 ORDER BY position ASC, id DESC The problem with this is that NULL entries for 'position' are treated as 0. Therefore all entries with position as NULL appear before those with 1,2,3,4. eg: NULL, NULL, NULL, 1, 2, 3, 4 I...
MySQL has an undocumented syntax to sort nulls last. Place a minus sign (-) before the column name and switch the ASC to DESC: SELECT * FROM tablename WHERE visible=1 ORDER BY -position DESC, id DESC It is essentially the inverse of position DESC placing the NULL values last but otherwise the same as position ASC. A ...
MySQL
2,051,602
348
How can I install the MySQLdb module for Python using pip?
It's easy to do, but hard to remember the correct spelling: pip install mysqlclient If you need 1.2.x versions (legacy Python only), use pip install MySQL-python Note: Some dependencies might have to be in place when running the above command. Some hints on how to install these on various platforms: Ubuntu 14, Ubuntu ...
MySQL
25,865,270
347
For homebrew mysql installs, where's my.cnf? Does it install one?
There is no my.cnf by default. As such, MySQL starts with all of the default settings. If you want to create your own my.cnf to override any defaults, place it at /etc/my.cnf. Also, you can run mysql --help and look through it for the conf locations listed. Default options are read from the following files in the giv...
MySQL
7,973,927
346
The following query: SELECT * FROM `objects` WHERE (date_field BETWEEN '2010-09-29 10:15:55' AND '2010-01-30 14:15:55') returns nothing. I should have more than enough data to for the query to work though. What am I doing wrong?
Your second date is before your first date (ie. you are querying between September 29 2010 and January 30 2010). Try reversing the order of the dates: SELECT * FROM `objects` WHERE (date_field BETWEEN '2010-01-30 14:15:55' AND '2010-09-29 10:15:55') Official Docs: https://dev.mysql.com/doc/refman/8.0/en/datetime.html
MySQL
3,822,648
344
How can I generate a create table script for an existing table in phpmyadmin?
Use one of the following queries in sql tab: SHOW CREATE TABLE tablename; SHOW CREATE TABLE database.tablename; To view full query There is this Hyperlink named +Options left above, There select Full Texts
MySQL
11,739,014
341
I'm rewriting a project to use Node.js. I'd like to keep using MySQL as the DB (even though I don't mind rewriting the schema). I'm looking for a simple-to-use, reasonable-performance ORM, which supports caching, many-to-one and many-to-many relations. From the MySQL ORMs I could find, persistencejs and sequelize seem ...
I would choose Sequelize because of it's excellent documentation. It's just a honest opinion (I never really used MySQL with Node that much).
MySQL
6,007,353
341
I can read the MySQL documentation and it's pretty clear. But, how does one decide which character set to use? On what data does collation have an effect? I'm asking for an explanation of the two and how to choose them.
From MySQL docs: A character set is a set of symbols and encodings. A collation is a set of rules for comparing characters in a character set. Let's make the distinction clear with an example of an imaginary character set. Suppose that we have an alphabet with four letters: 'A', 'B', 'a', 'b'. We give e...
MySQL
341,273
341
At what point does a MySQL database start to lose performance? Does physical database size matter? Do number of records matter? Is any performance degradation linear or exponential? I have what I believe to be a large database, with roughly 15M records which take up almost 2GB. Based on these numbers, is there any in...
The physical database size doesn't matter. The number of records don't matter. In my experience the biggest problem that you are going to run in to is not size, but the number of queries you can handle at a time. Most likely you are going to have to move to a master/slave configuration so that the read queries can ru...
MySQL
1,276
341
Given an array of ids $galleries = array(1,2,5) I want to have a SQL query that uses the values of the array in its WHERE clause like: SELECT * FROM galleries WHERE id = /* values of array $galleries... eg. (1 || 2 || 5) */ How can I generate this query string to use with MySQL?
BEWARE! This answer contains a severe SQL injection vulnerability. Do NOT use the code samples as presented here, without making sure that any external input is sanitized. $ids = join("','",$galleries); $sql = "SELECT * FROM galleries WHERE id IN ('$ids')";
MySQL
907,806
339
I installed MySQL on Mac OS X Mountain Lion with homebrew install mysql, but when I tried mysql -u root I got the following error: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) What does this error mean? How can I fix it?
You'll need to start MySQL before you can use the mysql command on your terminal. To do this, run brew services start mysql. By default, brew installs the MySQL database without a root password. To secure it run: mysql_secure_installation. To connect run: mysql -uroot. root is the username name here.
MySQL
15,450,091
336
I have a WordPress website on my local WAMP server. But when I upload its database to live server, I get error #1273 – Unknown collation: ‘utf8mb4_unicode_520_ci’
I believe this error is caused because the local server and live server are running different versions of MySQL. To solve this: Open the sql file in your text editor Find and replace all utf8mb4_unicode_520_ci with utf8mb4_unicode_ci Save and upload to a fresh mySql db
MySQL
42,385,099
335
Migration error on Laravel 5.4 with php artisan make:auth [Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter tabl ...
According to the official Laravel 7.x documentation, you can solve this quite easily. Update your /app/Providers/AppServiceProvider.php to contain: use Illuminate\Support\Facades\Schema; /** * Bootstrap any application services. * * @return void */ public function boot() { Schema::defaultStringLength(191); } ...
MySQL
42,244,541
335