- How can I get a list of user accounts using the command line in MySQL?
- 16 Answers 16
- Show all users in a table and delete those selected
- How do I get a list of active users with PHP?
- 2 Answers 2
- Как сделать вывод пользователей из БД и их данные?
- Здраствуйте!
- Displaying a online user list using PHP
- My codes current ability.
- Where the problem stands.
- What the code bellow does.
- Where the problem stands.
- The following is the java code.
- Now there is the PHP document code
- The above code
- The real issue and where i am asking for your help with please.
How can I get a list of user accounts using the command line in MySQL?
I’m using the MySQL command-line utility and can navigate through a database. Now I need to see a list of user accounts. How can I do this? I’m using MySQL version 5.4.1.
@Mustapha Why the title change? This answers here are SQL you can run from anywhere, not just a command line. And what does that tag add to the question?
The purpose of my edit was to maintain consistency between the title and the description, but I think you have a good point. Make your edit Mr. @Rup
16 Answers 16
SELECT User FROM mysql.user;
Which will output a table like this:
As Matthew Scharley points out in the comments on this answer, you can group by the User column if you’d only like to see unique usernames.
I think it may be necessary to group on User too, to only get unique user values, since there’s a seperate row for each user @ host entry.
@barrycarter DELETE FROM mysql.user; better have WHERE user=’someuser’ and host=’somehost’; If you do DELETE FROM mysql.user; , all users are gone. Logins after the next mysql restart or FLUSH PRIVILEGES; eliminate users from memory. Here is an example of one of my posts on doing DELETE FROM mysql.user responsibly : dba.stackexchange.com/questions/4614/…
I find this format the most useful as it includes the host field which is important in MySQL to distinguish between user records.
select User,Host from mysql.user;
@Packer the host comes into play when you are connecting from a different server. It is possible to grant different access to ‘packer’@’example.com’ and ‘packer’@’google.com’
A user account comprises the username and the host level access.
Therefore, this is the query that gives all user accounts
SELECT CONCAT(QUOTE(user),'@',QUOTE(host)) UserAccount FROM mysql.user;
This is basically the same as spkane’s answer. What is the benefit of concatenating the user and host columns?
One example: the user@host format is used for setting passwords. Omitting the host from the SET PASSWORD command produces an error. SET PASSWORD FOR wordpressuser = PASSWORD(‘. ‘); produces the error ERROR 1133 (42000): Can’t find any matching row in the user table . Include the host and it works. SET PASSWORD FOR wordpressuser@localhost = PASSWORD(‘. ‘); produces Query OK, 0 rows affected (0.00 sec) .
Best answer, whatever the naysayers may complain about. Only thing i’d change were appending an ORDER BY user to it.
Show all users in a table and delete those selected
how can I show all the users in the users table in the database in a html table? I have to show all the users in a html table and each user can be selected using a check box. The selected users are then deleted from the database. I am using the technique mvc and I have a page «DeleteUser» that contains only the html, a controller and a public file. View/DeleteUser.php contains:
$controller = new DeleteUserController(); $view = $controller->invoke(); $view->render();
class DeleteUserController < public $user; public $users; public $userRepository; public $view; public function __construct() < $username = $_SESSION['username']; $this->userRepository = new UserRepository(); $this->user = $this->userRepository->findByUsername($username); $this->users = array(); $this->view = new View('DeleteUser'); $db = Database::getInstance(); > public function listUsers() < $this->users = $this->userRepository->fetchAll(); foreach($this->users as $u) < $str = "getId() ?> "; > > public function deleteUsers() < if(isset($_POST['submit-deleteuser'])) < $del_id = $_POST['users']; foreach($del_id as $value) < $value->delete(); > > > public function work() < $this->listUsers(); $this->deleteUsers(); > public function invoke() < $this->work(); $this->view->setData('user', $this->user); return $this->view; >
# Username Fisrt name Last name City Gender E-mail Check $row[id] $row[username] $row[fisrt_name] $row[last_name] $row[city] $row[gender] $row[email] "; > > ?>
But now I do not know how to do. The two methods listUsers() and deleteUsers() are wrong and do not know how to complete them or correct them. First it was simple, I put the php code that showed users in the html tag that I wanted (
) but now? I do not know how to handle this thing. Give me advice? Thank you 🙂 fetchAll() is:
public function fetchAll()< $db = Database::getInstance(); $stmt = $db->prepare("SELECT * FROM `users`"); $stmt->execute(); $users = array(); while($result = $stmt->fetch()) < $users[] = User::load($result); >return $users; >
How do I get a list of active users with PHP?
I currently maintain a DB table of users, when after logging in I update the table with their ID and login_time. This works to a point but currently I can’t tell if the user has been active since the login or for how long. Is there a better way to get a complete list of users that have been active in the past X minutes?
You could add a «last seen» column in the table and refresh that every time the user makes a new request
Making a DB request should be okay for most sites. If you have huge traffic, you might want to switch to a memcache at some point, but a database call shouldn’t cause any performance problems for a site with low to medium traffic. Any CMS-driven site without static caching makes dozens of them on every request
@Paul, The end of a «visit» can only be defined by an explicit logout or a timeout. Take a look here: stackoverflow.com/questions/679657/find-number-of-open-sessions
2 Answers 2
The best way to get what you need would be a «Last Activity» column in the users table. You would just update it whenever a user access a page. Depending on what information you need it could replace the login_time column or it could be a new column.
You’ll have to keep track of when the user made their last request in your database as a separate table or column. You can then formulate a query to select, e.g. all users that have made a request in the last 5 minutes.
PHP itself does not store — or care for — that kind of information. Unless you happen to have your own session management module which does store this kind of information, then you could use data from that.
Как сделать вывод пользователей из БД и их данные?
Как сделать вывод пользователей из БД
Здравствуйте помогите пожалуйста как вывести список пользователей из бд CREATE TABLE IF NOT.
Как сделать вывод аватарки всех пользователей?
Нужно сделать вывод аватарки,получилось сделать только вывод название загруженого файла но не саму.
Как сделать вывод всех пользователей пока поле пустое?
Есть поиск пользователей написан на php,html,js при вводе в поле имя выводит пользователя но пока.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
function LoadDataUsers() // Загрузка списка юзеров { $query = mysql_query("SELECT id, fio FROM sobstvenniki"); $array = mysql_fetch_array($query); do { echo "\"?id_user=".$array['id'].">".$array['id']." ".$array['fio'].""; } while($array = mysql_fetch_array($query)); } function CurrentUser($id_user) //Вывод инфы по конкретному пользователю { if(empty($id_user)) { echo "Юзер не выбран"; } else { $query = mysql_query("SELECT * FROM sobstvenniki WHERE "); $array = mysql_fetch_array($query); return $array; } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
session_start(); ?> Здраствуйте!
$db = mysql_connect("localhost", "root"); mysql_select_db("diplomnaya",$db); function LoadDataUsers() // Загрузка списка юзеров { $query = mysql_query("SELECT id, fio FROM sobstvenniki"); $array = mysql_fetch_array($query); do { echo "\"?id_user=".$array['id'].">".$array['id']." ".$array['fio'].""; } while($array = mysql_fetch_array($query)); } function CurrentUser($id_user) //Вывод инфы по конкретному пользователю { if(empty($id_user)) { echo "Юзер не выбран"; } else { $query = mysql_query("SELECT * FROM sobstvenniki WHERE "); $array = mysql_fetch_array($query); return $array; } } ?>
Подвал