Difference between revisions of "SQL"

From Organic Design wiki
m (Fixing crashed tables)
(Dealing with duplicates on import: see Backup)
Line 12: Line 12:
  
 
== Dealing with duplicates on import ==
 
== Dealing with duplicates on import ==
Sometimes dumps have problems where a row with a that should be unique has one or more duplicate entries. Mysql can be called with the '''-f''' option which makes it continue importing after these occurrences, but the problem is that the SQL directive that contained the error cannot continue and it goes straight to the next line of SQL. The dumps contain a single SQL command that populates an entire table, so that means the row before duplicate will be the last thing imported into that table.
+
See [[Backup]]
 
 
To handle this scenario, you can edit the dump and remove the line in the table definition that forces the column to be unique, then import the data again and manually remove the duplicates, then alter the table to put the unique requirement back. The dumps can be very large and difficult to edit, so I use perl to remove the duplicate with something like the following:
 
{{code|<perl>open DB, '<', 'dump.sql';
 
while( <DB> ) { print $_ unless /UNIQUE KEY `name_title` \(`page_namespace`,`page_title`\)/ }
 
</perl>}}
 
  
 
== Reset a password ==
 
== Reset a password ==

Revision as of 14:14, 12 July 2014

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!

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.

<bash>mysqlcheck --auto-repair DBNAME -u USER -p</bash>

Dealing with duplicates on import

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.

{{{1}}}

Note that the password is a nested concatenation of both the md5 of the user_id combined with the md5 password.

Now update that users password:

{{{1}}}

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:

{{{1}}}

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 [1] 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

MySQL vs MSSQL

MySQL News & Information

RODBC

Using RODBC to interact with R requires the user to configure the system as described in the file README after installing RODBC.

See

Towards SQL for P2P environments