how to log in to mysql and query the database from linux terminal

后端 未结 12 2751
野趣味
野趣味 2020-12-04 06:47

I am using debian linux. I have a linux machine on which mysql is install. I can log in to my linux machine using root user as well as other user. I can connect to mysql dat

12条回答
  •  无人及你
    2020-12-04 07:18

    To your first question:

    mysql -u root -p
    

    or

    mysqladmin -u root -p "your_command"
    

    depending on what you want to do. The password will be asked of you once you hit enter! I'm guessing you really want to use mysql and not mysqladmin.

    For restarting or stopping the MySQL-server on linux, it depends on your installation, but in the common debian derivatives this will work for starting, stopping and restarting the service:

    sudo /etc/init.d/mysql start
    sudo /etc/init.d/mysql stop
    sudo /etc/init.d/mysql restart
    sudo /etc/init.d/mysql status
    

    In some newer distros this might work as well if MySQL is set up as a deamon/service.

    sudo service mysql start
    sudo service mysql stop
    sudo service mysql restart
    sudo service mysql status
    

    But the question is really impossible to answer without knowing your particular setup.

提交回复
热议问题