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

后端 未结 12 2130
野趣味
野趣味 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:09

    At the command prompt try:

    mysql -u root -p
    

    give the password when prompted.

    0 讨论(0)
  • 2020-12-04 07:12

    I had the same exact issue on my ArchLinux VPS today.

    mysql -u root -p just didn't work, whereas mysql -u root -pmypassword did.

    It turned out I had a broken /dev/tty device file (most likely after a udev upgrade), so mysql couldn't use it for an interactive login.

    I ended up removing /dev/tty and recreating it with mknod /dev/tty c 5 1 and chmod 666 /dev/tty. That solved the mysql problem and some other issues too.

    0 讨论(0)
  • 2020-12-04 07:15

    if u got still no access to db, 1. in ur error message is set no password right? then first do mysqlpasswd 'username' after that enter and then give it a password type again as requested and then try to access again with mysql -p if you are root

    0 讨论(0)
  • 2020-12-04 07:18

    1.- How do I get mysql prompt in linux terminal?

    mysql -u root -p
    

    At the Enter password: prompt, well, enter root's password :)

    You can find further reference by typing mysql --help or at the online manual.

    2. How I stop the mysql server from linux terminal?

    It depends. Red Hat based distros have the service command:

    service mysqld stop
    

    Other distros require to call the init script directly:

    /etc/init.d/mysqld stop
    

    3. How I start the mysql server from linux terminal?

    Same as #2, but with start.

    4. How do I get mysql prompt in linux terminal?

    Same as #1.

    5. How do I login to mysql server from linux terminal?

    Same as #1.

    6. How do I solve following error?

    Same as #1.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-04 07:21

    In Ubuntu, all I have to do ran is sudo mysql in GNOME terminal and that's it. I can start making databases or query a data in table, etc.

    0 讨论(0)
提交回复
热议问题