Every time I have to setup users in MySQL I seem to have problems.
I was setting up a system to do some WordPress testing and installed MySQL OK, but ran into problems with the users and permissions. Again.
So I had to search the net, again, and find out what I was doing wrong, again.
Maybe I’m just used to the way oracle does it, my MySQL does it in a strange way, why is it so hard ?
Read More »
If you are trying to get PHP, Apache and MySQL to work together one of the steps you have to do is edit the file
/etc/php5/apache2/php.ini and uncomment the following line,
extensions = mysql.so
You then need to commented out the following lines,
;extension_dir = /usr/lib/php4/20020429-zts/
;include_path = ".:/usr/share/php"
NOTE : These are the only steps of course, its just one of the traps I came across while trying setup a server.
I’ve been looking at foreign key constraints today. I’ve managed to set a FK constraint in an Oracle and a MySQL database without too much trouble. But I was having trouble understanding why you would set up a FK constraint. It seems some of the reasons are: –
- ensure referential integrity
- assist with visualizing and preparing database diagrams
- may assist with performance
- assist programmers by requiring less code.
I did some testing in Oracle and MySQL to make sure i understand how they work and it was a very interesting learning expierence.
Here’s what I did. First you need to create two tables. All SQL is for Oracle, minor editing my be required to get it to work in MySql or other DBMS systems.
-- Create Subjects table with PK on Subject column
CREATE TABLE STATES ( STATE VARCHAR(4) NOT NULL,
CONSTRAINT PK_STATE PRIMARY KEY (STATE) );
-- Create TIPS table with PK and FK
CREATE TABLE CITIES ( CITYID NUMBER(5) NOT NULL,
CITY VARCHAR2(20) NOT NULL,
STATE VARCHAR2(4) NOT NULL,
CONSTRAINT PK_CITYID PRIMARY KEY (CITYID) VALIDATE ,
CONSTRAINT FK_STATE FOREIGN KEY (STATE)
REFERENCES STATES (STATE) ON DELETE CASCADE);
-- Insert data into subject table
insert into STATES values ('QLD');
insert into STATES values ('VIC');
-- Insert data into tips table
insert into CITIES values (1,'Brisbane','QLD');
insert into CITIES values (2,'Melbourne','VIC');
-- show data
select * from STATES;
select * from CITIES;
If you now delete the row containing the value ‘VIC’ from the STATES table,
DELETE FROM STATES where STATE = ‘VIC’;
it will also delete all rows in the CITIES table that have a value of ‘VIC’ in the STATE column.
Conversely, if you delete all rows in CITIES table that contain ‘VIC’ in the STATES column, the row for ‘VIC’ is NOT deleted from the from STATES table.
This type of thing also works in MySQL but only if you are using the InnoDB storage engine for your table(s), not the default MyISAM engine.
I did some digging and found out that Postgres is actually PostgreSQL an open source database. Much like MySQL.
I setup a spare laptop with Fedora 10 and installed it and got it running OK with only a few little hitches. Mostly from not knowing a thing about it.
Looks like it would be simple enough to use, it would just be a matter of learning the new syntax for everything.
I happened to have a quick look at the jobs available at the Bureau of Meteorology yesterday. They have a “Systems and Database Specialist” position available starting at $80K.
Although I’m not going to apply for it, it has given me some ideas on how/where to improve my skills.
- Database Tuning
- AIX (not sure how I’m going to do this)
- Postgres (not even sure what this is !)
I’ve had a few problems creating users, assigning passwords and granting access to uses in MySQL.
Below is one method I’ve found that works, at least for WordPress databases.
mysql> create database wordpressdb;
mysql> create user 'wordpressuser'@'localhost';
mysql> set password for 'wordpressuser'@'localhost'=PASSWORD('password');
mysql> use wordpressdb;
mysql> grant all on * to 'wordpressuser'@'localhost';
To run a script from within mysql simply to the following
mysql> source d:/my documents/run.sql;
Where d:/my documents/run.sql is the path and name of the script you want to run.