Add Magento Admin User Using MySQL Script


How to add Magento Admin User Using MySQL Script ?

Here is the very simple answer to this question. This script quickly adds a Magento Admin user directly into the database. It is possible to run this script from the command line or by copying and pasting into phpMyAdmin. Most of these fields are trivial, I’m just listing them so you don’t miss anything.

  1. Set the salt portion of your password. You’ll rarely need to change this. If you do, just use two lower case letters of your choice.
  2. Set your password. At least 8 characters in length and at least one digit.
  3. Firstname: Enter admin’s first name.
  4. Lastname: Enter admin’s last name.
  5. Enter email of admin user.
  6. Enter username where ‘myuser’ is set. Notice ‘myuser’ shows up in two places.
  7. Enter Firstname again. This is more symbolic to label the rule.
LOCK TABLES `admin_role` WRITE , `admin_user` WRITE;
 
SET @SALT = "sid";
SET @PASS = CONCAT(MD5(CONCAT( @SALT , "password") ), CONCAT(":", @SALT ));
SELECT @EXTRA := MAX(extra) FROM admin_user WHERE extra IS NOT NULL;
 
INSERT INTO `admin_user` (firstname,lastname,email,username,password,created,lognum,reload_acl_flag,is_active,extra) 
VALUES ('Firstname','Lastname','email@example.com','myuser',@PASS,NOW(),0,0,1,@EXTRA);
 
INSERT INTO `admin_role` (parent_id,tree_level,sort_order,role_type,user_id,role_name) 
VALUES (1,2,0,'U',(SELECT user_id FROM admin_user WHERE username = 'myuser'),'Firstname');
 
UNLOCK TABLES;

And you’re done. Now you can login to your admin.. 🙂

Source: Activo

Advertisements

What are the different tables(Engine) present in MySQL, which one is default?


Following tables (Storage Engine) we can create :
1. MyISAM (Each MyISAM table is stored on disk in three files. The files have names that begin with the table name and have an extension to indicate the file type. An .frm file stores the table format. The data file has an .MYD (MYData) extension. The index file has an .MYI (MYIndex) extension. )
2. InnoDB (The default storage engine IN MYSQL) (InnoDB is a transaction-safe (ACID compliant) storage engine for MySQL that has commit, rollback, and crash-recovery capabilities to protect user data.)
3. Merge
4. Heap (MEMORY) (The MEMORY storage engine creates tables with contents that are stored in memory. Formerly, these were known as HEAP tables. MEMORY is the preferred term, although HEAP remains supported for backward compatibility. )
5. BDB (BerkeleyDB) (Sleepycat Software has provided MySQL with the Berkeley DB transactional storage engine. This storage engine typically is called BDB for short. BDB tables may have a greater chance of surviving crashes and are also capable of COMMIT and ROLLBACK operations on transactions)
6. EXAMPLE
7. FEDERATED (It is a storage engine that accesses data in tables of remote databases rather than in local tables. )
8. ARCHIVE (The ARCHIVE storage engine is used for storing large amounts of data without indexes in a very small footprint. )
9. CSV (The CSV storage engine stores data in text files using comma-separated values format.)
10. BLACKHOLE (The BLACKHOLE storage engine acts as a “black hole” that accepts data but throws it away and does not store it. Retrievals always return an empty result)

What is PHP’s mysqli Extension?


The mysqli extension, or as it is sometimes known, the MySQL improved extension, was developed to take advantage of new features found in MySQL systems versions 4.1.3 and newer. The mysqli extension is included with PHP versions 5 and later.

The mysqli extension has a number of benefits, the key enhancements over the mysql extension being:
=>Object-oriented interface
=>Support for Prepared Statements
=>Support for Multiple Statements
=>Support for Transactions
=>Enhanced debugging capabilities
=>Embedded server support

Duplicates Records in Multiple Fields with MySql


Retrieving count of Duplicated Records

SELECT firstname, lastname, COUNT(*)
FROM staff
GROUP BY firstname, lastname
HAVING COUNT(*) > 1
ORDER BY COUNT(*) DESC;

Retrieving The Individual Duplicated Records

SELECT stafftable.firstname, stafftable.lastname
FROM staff stafftable
INNER JOIN (
SELECT firstname, lastname, COUNT(*)
FROM staff
GROUP BY firstname, lastname
HAVING COUNT(*) > 1) temp
ON temp.firstname = stafftable.firstname
AND temp.lastname = stafftable.lastname
ORDER BY firstname, lastname

Difference between mysql_connect() and mysql_pconnect()


Shruti's Space

mysql_connect() and mysql_pconnect() both are working for database connection but with little difference. In mysql_pconnect(), ‘p’ stands for persistance connection.

When we are using mysql_connect() function, every time it is opening and closing the database connection, depending on the request .

But in case of mysql_pconnect() function,
First, when connecting, the function would try to find a (persistent) connection that’s already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.
Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the connection will remain open for future use (mysql_close() will not close connection established by mysql_pconnect()).

mysql_pconncet() is useful when you have a lot of traffice on your site. At that time for every request it will not open a connection but will take it…

View original post 33 more words

Get data of yesterday, tomorrow and last week by Mysql query from Database


To get Yesterday’s data from the database table

  1. mysql_query("select * from table where date = ".date("Y-m-d", strtotime("-1 day")));
  2. mysql_query(“select * from table where date = NOW()-INTERVAL 1 DAY”);

To get Tomorrow’s data

  1. mysql_query(“select * from table where date = “.date(“Y-m-d”, strtotime(“+1 day”)));
  2. mysql_query(“select * from table where date = NOW()+INTERVAL 1 DAY”);

To get Last Week data

mysql_query(“select * from tbl where date between NOW() – INTERVAL DAYOFWEEK(NOW())+6 DAY AND NOW() – INTERVAL DAYOFWEEK(NOW())-1 DAY”);

Can we have multiple primary keys in a single table?


No we Cannot.
For example,

CREATE TABLE IF NOT EXISTS `usr` (
`id` int(11) NOT NULL,
`survey_id` int(11) NOT NULL,
`number` int(11) NOT NULL,
`count` int(11) NOT NULL,
`date` date NOT NULL,
PRIMARY KEY (`id`,`survey_id`,`number`,`count`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Basically, this appears to be creating four primary key on one table.

We could create a number of unique keys in one table, but only one primary key.

Then how is it that your system is allowing the creation of multiple primary keys?

Think of it like it suggest, a ‘KEY’. So the key would be all of the columns specified. In your case you can have multiple rows with the same ‘ID’ and multiple rows with the same ‘survey_id’ but there shall never be two rows that have the same ‘ID’ AND ‘survey_id’.

So in this case it is not saying that the column ‘ID’ must be unique nor is it saying that ‘survey_id’ must be unique, but only the combination.

Like if you write an query

INSERT INTO `usr` (`id`, `survey_id`, `number`, `count`, `date`) VALUES (1, 1, 123456, 50, ‘2013-04-01’);

And after this you again run this query then you are getting an error “#1062 – Duplicate entry ‘1-1-123456-50’ for key ‘PRIMARY'”