Difference between revisions of "SQL"

From Organic Design wiki
(Dealing with duplicates on import: see Backup)
(rm old info and add intro to joins)
(7 intermediate revisions by 2 users not shown)
Line 6: Line 6:
 
== Backup & restore ==
 
== Backup & restore ==
 
See [[backup]] for details about this as it's doesn't outside the SQL environment so doesn't belong in this article. But don't forget to set the default character set to the same as the dump used when you import the data!
 
See [[backup]] for details about this as it's doesn't outside the SQL environment so doesn't belong in this article. But don't forget to set the default character set to the same as the dump used when you import the data!
 +
 +
To restore only a single database from a full dump use the following:
 +
<source lang="bash">
 +
mysql -D DBNAME -o DBNAME < dump.sql
 +
</source>
  
 
== Fixing crashed tables ==
 
== Fixing crashed tables ==
 
To fix a crashed table just use '''repair TABLENAME''' from the MySQL command line, or to automatically scan all tables and fix them run the following from the shell.
 
To fix a crashed table just use '''repair TABLENAME''' from the MySQL command line, or to automatically scan all tables and fix them run the following from the shell.
{{code|<bash>mysqlcheck --auto-repair DBNAME -u USER -p</bash>}}
+
<source lang="bash">
 
+
mysqlcheck --auto-repair DBNAME -u USER -p
== Dealing with duplicates on import ==
+
</source>
See [[Backup]]
 
 
 
== Reset a password ==
 
With server side access to the mysql database you first need to identify the '''user_id''' of the '''username''' you want to reset.
 
{{Code|<PHP>
 
SELECT user_id,user_namefromuser
 
WHEREuser_name="WikiSysop";
 
</PHP>
 
}}
 
  
Note that the password is a nested concatenation of both the md5 of the '''user_id''' combined with the md5 password.
+
== Database procedures ==
 +
*[[Reset MySQL root password]]
 +
*[[Renaming MySQL tables and databases]]
 +
*[[Rename a MediaWiki database]]
 +
*[[Reset a wiki user password]]
 +
*[[Set a user preference]]
 +
*[[Manually backup a wiki]]
 +
*[[Add a wiki database]]
  
Now update that users password:
+
== See also ==
{{Code|<PHP>
+
*[[MariaDB]]
UPDATEuser
+
*[https://stackoverflow.com/questions/5836623/getting-lock-wait-timeout-exceeded-try-restarting-transaction-even-though-im Good thread on table lock problems and solutions]
SETuser_password=md5(CONCAT('1-',md5('password')))
+
*[http://tlug.dnho.net/?q=node/276 Convert a MySQL DB from latin1 to UTF8]
WHEREuser_id=1;
 
</PHP>
 
}}
 
 
 
Analternative way is if you know the users email address then you can identify the user and enable their email address so that the page [[Special:UserLogin]] can be used to '''Email-password''':
 
{{Code|<PHP>
 
UPDATEuser
 
SETuser_email="wikiSysops@email.address"
 
WHEREuser_id=1;
 
</PHP>
 
}}
 
 
 
===Reset or set a page hit counter===
 
UPDATEpageSETpage_counter=0WHEREpage_title='Main_Page';
 
 
 
===Adjust user groups===
 
INSERTINTOuser_groups(ug_user,ug_group)VALUES(999,'sysop');
 
 
 
==Selecting current articles by category==
 
See [http://upload.wikimedia.org/wikipedia/commons/4/41/Mediawiki-database-schema.pngMediaWikischema] for a description of the tables. Essentially '''categorylinks''' store the category member relationships, '''page''' identifies the title and metadata information, '''revision''' identifies all revisions of an article, and '''text''' contains the actual wikitext of articles. There is a one to many relationship between pages and revisions, and a one to many relationship between text and revisions.
 
 
 
The database schema used by MediaWiki allows variable article content to be stored as key => value pairs where the atomic unit for the content '''varies''' depending on the content of the article. A way around this is to use categorization to group common atomic unit structure together. Basically this is a filtering problem, however queried atomic unit structure needs to be checked downstream by any downstream processing of content within categories.
 
 
 
== Documentation ==
 
 
*[http://www.sql-tutorial.com/ SQL Tutorial] ''- A nice tutorial on SQL''
 
*[http://www.sql-tutorial.com/ SQL Tutorial] ''- A nice tutorial on SQL''
 
*[http://dev.mysql.com/doc/index.html Official MySQL Documentation]
 
*[http://dev.mysql.com/doc/index.html Official MySQL Documentation]
 
*[http://www.w3schools.com/sql/sql_join.asp W3C SQL Tutorial] [http://www.w3schools.com/sql/sql_quickref.asp (QuickRef)]
 
*[http://www.w3schools.com/sql/sql_join.asp W3C SQL Tutorial] [http://www.w3schools.com/sql/sql_quickref.asp (QuickRef)]
 
+
*[https://www.databasestar.com/sql-joins/ Introduction to SQL joins]
== MySQL vs MSSQL ==
 
 
*[http://www.x7media.com/resources/SQL_Differences_Between_Microsoft_SQL_Server_and_MySQL.asp List of common differences between MySQL and MSSQL]
 
*[http://www.x7media.com/resources/SQL_Differences_Between_Microsoft_SQL_Server_and_MySQL.asp List of common differences between MySQL and MSSQL]
 
== MySQL News & Information ==
 
*[http://dev.mysql.com/doc/falcon/en/falcon-overview.html Falcon Overview] ''- the new MySQL 6 Falcon storage engine''
 
*[http://dev.mysql.com/tech-resources/articles/mysql-storedprocedures.html MySQL Stored procedures & triggers]
 
 
== RODBC ==
 
Using RODBC to interact with R requires the user to configure the system as described in the file README after installing [http://cran.stat.auckland.ac.nz/web/packages/RODBC/index.html RODBC].
 
;See
 
*http://www.unixODBC.org
 
*http://www.easysoft.com/developer/interfaces/odbc/linux.html (tutorial using unixODBC)
 
 
== Towards SQL for P2P environments ==
 
*[[PeerPedia]]
 
*[[MediaWikiLite]]
 
*[https://mariadb.org/en/about/ MariaDB] ''- see [[PeerPedia]] Feb 2013 update for more info''
 
*[http://pier.cs.berkeley.edu The PIER Project]
 
*[[w:Prefix Hash Tree|Prefix Hash Trees]]
 
*[http://www.cs.huji.ac.il/~ittaia/papers/AAY-OPODIS05.pdf Skip B-Trees]
 
*[http://yoshinorimatsunobu.blogspot.com/2010/10/using-mysql-as-nosql-story-for.html Using MySQL as a NoSQL - A story for exceeding 750,000 qps on a commodity server] ''- Yoshinori Matsunobu's blog''
 

Revision as of 11:15, 8 June 2018

Broom icon.svg The content of this article requires cleaning up to meet OD's quality standards. Check the wiki best practices for guidelines on improving article and categorisation quality.

SQL (Structured Query Language) is a computer language used to create, retrieve, update and delete data from relational database management systems. SQL has been standardised by both ANSI and ISO.

SQL is commonly spoken either as the names of the letters ess-cue-el, or like the word sequel. The official pronunciation of SQL according to ANSI is ess-cue-el. However, each of the major database products (or projects) containing the letters SQL has its own convention: MySQL is officially and commonly pronounced "My Ess Cue El"; PostgreSQL is expediently pronounced postgres (being the name of the predecessor to PostgreSQL); and Microsoft SQL Server is commonly spoken as Microsoft-sequel-server. See MediaWikiLite for information about SQLite support in MediaWiki, or MSSQL for information about Microsoft SQL Server support. We're now using MariaDB for our SQL server which is a drop-in replacement for MySQL but is fully open source and more efficient too.

Backup & restore

See backup for details about this as it's doesn't outside the SQL environment so doesn't belong in this article. But don't forget to set the default character set to the same as the dump used when you import the data!

To restore only a single database from a full dump use the following:

mysql -D DBNAME -o DBNAME < dump.sql

Fixing crashed tables

To fix a crashed table just use repair TABLENAME from the MySQL command line, or to automatically scan all tables and fix them run the following from the shell.

mysqlcheck --auto-repair DBNAME -u USER -p

Database procedures

See also