Root, mysql, root - A simple explanation of users.
There seems to be a lot of confusion in the newbie crowd about the difference between MySQL and OS users. It works like this. Your operating system supports users. That’s who you log in as when prompted. When logged in you can start processes or programs. If I log into my linux box as user eric anything started by me is said to be running as user eric. There is a super user known as root that has total control over the system. It’s not a good idea to run processes as root because they have the power to change anything in the system both bad and good. When installing MySQL the install guide says to create a user known as ‘mysql’. This is a new user in the operating system just like user ‘eric’. One of the things root can do is start processes as other users. Mysqld will complain if you start it as root without telling it to change into another user after executing. This can be done with –user= on the command line or user=mysql in my.cnf When mysqld starts it starts as root but then turns itself into running as another user via the setuid() which means set user id.
Operating systems are good at keeping users out of files they don’t own and allowing them to manage their own processes but this isn’t enough for mysql. MySQL needs to be able to restrict users to databases, tables, and even columns. Since mysqld is running as the operating system user ‘mysql’ and it needs to track users from the outside world, it has to maintain it’s own users. These are MySQL users and are completely independent of the operating system users we just talked about. Unix operating systems have a super user and so does mysql. It’s named root by default.
operating system root -> mysqld running as system user mysql -> inside mysql root user -> mysql users.
MySQL can also have other users. Ones that are restricted to certain databases, tables, or columns. In an operating system your user privileges depend on your username and password. In mysql you are identified by your username, password, and where you are connecting from.
So your operating system has a user root and mysql has a user root. Your operating system has a normal user ‘eric’ and mysql has a normal user ‘eric’.