<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://beardedmaker.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Mysql</id>
		<title>Mysql - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://beardedmaker.com/wiki/index.php?action=history&amp;feed=atom&amp;title=Mysql"/>
		<link rel="alternate" type="text/html" href="https://beardedmaker.com/wiki/index.php?title=Mysql&amp;action=history"/>
		<updated>2026-04-26T17:51:52Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.27.4</generator>

	<entry>
		<id>https://beardedmaker.com/wiki/index.php?title=Mysql&amp;diff=150&amp;oldid=prev</id>
		<title>Beard: Created page with &quot;&lt;pre&gt; packages: 	mysql-server  daemons: 	mysqld  configs: 	/etc/my.cnf - main config file 	/var/lib/mysql/mysql.sock - socket 	/var/lib/mysql/ - data/log directory (centos) 	~...&quot;</title>
		<link rel="alternate" type="text/html" href="https://beardedmaker.com/wiki/index.php?title=Mysql&amp;diff=150&amp;oldid=prev"/>
				<updated>2016-02-29T21:23:13Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;pre&amp;gt; packages: 	mysql-server  daemons: 	mysqld  configs: 	/etc/my.cnf - main config file 	/var/lib/mysql/mysql.sock - socket 	/var/lib/mysql/ - data/log directory (centos) 	~...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
packages:&lt;br /&gt;
	mysql-server&lt;br /&gt;
&lt;br /&gt;
daemons:&lt;br /&gt;
	mysqld&lt;br /&gt;
&lt;br /&gt;
configs:&lt;br /&gt;
	/etc/my.cnf - main config file&lt;br /&gt;
	/var/lib/mysql/mysql.sock - socket&lt;br /&gt;
	/var/lib/mysql/ - data/log directory (centos)&lt;br /&gt;
	~/.mysql_history - command history log&lt;br /&gt;
&lt;br /&gt;
ports:&lt;br /&gt;
	tcp 3306&lt;br /&gt;
&lt;br /&gt;
other:&lt;br /&gt;
	\ - escape char&lt;br /&gt;
	* - wild&lt;br /&gt;
	% - wild in &amp;quot;like&amp;quot; string matching&lt;br /&gt;
	0x'1234' - hex literal&lt;br /&gt;
	0b'1010' - bit literal&lt;br /&gt;
&lt;br /&gt;
commands:&lt;br /&gt;
	mysql - opens a mysql shell&lt;br /&gt;
	mysql -u &amp;lt;user&amp;gt; -p - open shell as user and prompt for password&lt;br /&gt;
		-h &amp;lt;host&amp;gt; - specify host&lt;br /&gt;
	mysql &amp;lt;database&amp;gt; &amp;lt; script.sql - execute script&lt;br /&gt;
	/usr/bin/mysql_secure_installation v- wizard for implementing secure mysql (say yes to all for most secure)&lt;br /&gt;
&lt;br /&gt;
backing up:&lt;br /&gt;
	mysqldump -p --all-databases - dumps sql scripts to stdout&lt;br /&gt;
	mysqldump -p &amp;lt;database&amp;gt; - dumps a specific database&lt;br /&gt;
	mysqldump -p --databases &amp;lt;database&amp;gt; &amp;lt;database&amp;gt; - dumps multiple databases&lt;br /&gt;
	mysqldump -p &amp;lt;database&amp;gt; &amp;lt;table&amp;gt; &amp;lt;table&amp;gt; - dumps specific tables in a database&lt;br /&gt;
		--opt - optimize for reading data later&lt;br /&gt;
		--no-data - only dump table structures&lt;br /&gt;
&lt;br /&gt;
	mysqlhotcopy -u &amp;lt;user&amp;gt; -p &amp;lt;password&amp;gt; &amp;lt;database&amp;gt; /path/to/dir/ - most efficient backup method. username/password required. directory must exist.&lt;br /&gt;
&lt;br /&gt;
remote administration:&lt;br /&gt;
	- on server, edit /etc/my.cnf and add line 'bind-address=&amp;lt;local-server-addr&amp;gt;'&lt;br /&gt;
	- in /etc/my.cnf make sure line 'skip-networking' is commented out with #&lt;br /&gt;
	- restart mysqld daemon&lt;br /&gt;
	- enter the mysql shell and the main database with 'mysql -p mysql'&lt;br /&gt;
	- type: update db set Host='&amp;lt;remote-client-addr&amp;gt;' where Db='&amp;lt;database&amp;gt;';&lt;br /&gt;
	- type: update user set Host='&amp;lt;remote-client-addr&amp;gt;' where user='&amp;lt;user&amp;gt;';&lt;br /&gt;
	- open up tcp port 3306 on the firewall&lt;br /&gt;
	- connect using 'mysql -u &amp;lt;user&amp;gt; -h &amp;lt;server-addr&amp;gt; -p&lt;br /&gt;
&lt;br /&gt;
mysql shell commands:&lt;br /&gt;
	create user &amp;lt;user&amp;gt;@&amp;lt;host&amp;gt;; - create new user&lt;br /&gt;
	set password for 'root'@'localhost' = md5('&amp;lt;password&amp;gt;'); - sets password for root&lt;br /&gt;
	drop user &amp;lt;user&amp;gt;@&amp;lt;host&amp;gt;; - delete user&lt;br /&gt;
	grant &amp;lt;privilege&amp;gt; on &amp;lt;component&amp;gt; to &amp;lt;user&amp;gt;; - grant privileges to user&lt;br /&gt;
		privileges: all privileges, file, reload, alter, index, select, create, insert, shutdown, delete, process, update, drop, references, usage&lt;br /&gt;
		components: table_name, *, *.*, db_name.*&lt;br /&gt;
		users: username, username@host&lt;br /&gt;
	revoke &amp;lt;privilege&amp;gt; on &amp;lt;component&amp;gt; from &amp;lt;user&amp;gt;; - revokes priveleges&lt;br /&gt;
	show grants for &amp;lt;user&amp;gt;@&amp;lt;host&amp;gt;; - shows user's priveleges&lt;br /&gt;
	select user(); - show current user&lt;br /&gt;
&lt;br /&gt;
	create database &amp;lt;database&amp;gt;;&lt;br /&gt;
	use &amp;lt;database&amp;gt;; - work with specified database&lt;br /&gt;
	show databases;&lt;br /&gt;
	show tables from &amp;lt;database&amp;gt;;&lt;br /&gt;
	show columns from &amp;lt;table&amp;gt;;&lt;br /&gt;
	select version();&lt;br /&gt;
	select now(); - current date and time&lt;br /&gt;
	select database(); - show current database&lt;br /&gt;
&lt;br /&gt;
	delete from &amp;lt;table&amp;gt; where &amp;lt;table&amp;gt;.&amp;lt;column&amp;gt; = '&amp;lt;string&amp;gt;'; - delete a record&lt;br /&gt;
	delete from &amp;lt;table&amp;gt; where 1=1; - clear a table&lt;br /&gt;
	drop table &amp;lt;table&amp;gt;; - delete a table&lt;br /&gt;
	drop database &amp;lt;database&amp;gt;; - delete a database&lt;br /&gt;
&lt;br /&gt;
	show global variables;&lt;br /&gt;
	show global variables like &amp;quot;max\_%&amp;quot;; - shows global variables starting with &amp;quot;max_&amp;quot;&lt;br /&gt;
	set @&amp;lt;variable&amp;gt; = &amp;lt;value&amp;gt;; - define variables for shell session. vars start with '@'. can use '=' or ':='.&lt;br /&gt;
	select @&amp;lt;variable&amp;gt; - cannot use '=' in select statement, must use ':='.&lt;br /&gt;
&lt;br /&gt;
default tables:&lt;br /&gt;
	mysql - contains privilege tables&lt;br /&gt;
	information_schema - contains environment variables&lt;br /&gt;
&lt;br /&gt;
tips:&lt;br /&gt;
	to cancel a multi-line command, type \c&lt;br /&gt;
&lt;br /&gt;
constraints:&lt;br /&gt;
	zerofill - pads int types with 0s. zerofill must be the first constraint. zerofill automatically implies &amp;quot;unsigned&amp;quot;&lt;br /&gt;
	auto_increment - used for numbers.&lt;br /&gt;
	default 'value' - specifies a default value to be inserted if nothing else is inserted.&lt;br /&gt;
	primary key&lt;br /&gt;
	unique&lt;br /&gt;
	not null&lt;br /&gt;
&lt;br /&gt;
references:&lt;br /&gt;
	primary key (id)&lt;br /&gt;
	foreign key (name1, name2) references table(nameA, nameB) on update cascade on delete restrict&lt;br /&gt;
&lt;br /&gt;
example scripts:&lt;br /&gt;
&lt;br /&gt;
create table web_user(&lt;br /&gt;
id		int(6)		not null primary key auto_increment,&lt;br /&gt;
username	varchar(20)	not null unique,&lt;br /&gt;
password	varchar(100)	not null,&lt;br /&gt;
email		varchar(100)	null unique,&lt;br /&gt;
phone		numeric(10)	null&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
insert into web_user(username,password,email,phone) values('bob',password('password'),'bob@project.com','3605551234');&lt;br /&gt;
insert into web_user(username,password,email,phone) values('tim',password('herp'),'tim@project.com','3605552345');&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
CREATE TABLE product (category INT NOT NULL, id INT NOT NULL,&lt;br /&gt;
                      price DECIMAL,&lt;br /&gt;
                      PRIMARY KEY(category, id)) ENGINE=INNODB;&lt;br /&gt;
CREATE TABLE customer (id INT NOT NULL,&lt;br /&gt;
                       PRIMARY KEY (id)) ENGINE=INNODB;&lt;br /&gt;
CREATE TABLE product_order (no INT NOT NULL AUTO_INCREMENT,&lt;br /&gt;
                            product_category INT NOT NULL,&lt;br /&gt;
                            product_id INT NOT NULL,&lt;br /&gt;
                            customer_id INT NOT NULL,&lt;br /&gt;
                            PRIMARY KEY(no),&lt;br /&gt;
                            INDEX (product_category, product_id),&lt;br /&gt;
                            FOREIGN KEY (product_category, product_id)&lt;br /&gt;
                              REFERENCES product(category, id)&lt;br /&gt;
                              ON UPDATE CASCADE ON DELETE RESTRICT,&lt;br /&gt;
                            INDEX (customer_id),&lt;br /&gt;
                            FOREIGN KEY (customer_id)&lt;br /&gt;
                              REFERENCES customer(id)) ENGINE=INNODB;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Beard</name></author>	</entry>

	</feed>