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

后端 未结 12 2131
野趣味
野趣味 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:22
    1. you should use mysql command. It's a command line client for mysql RDBMS, and comes with most mysql installations: http://dev.mysql.com/doc/refman/5.1/en/mysql.html

    2. To stop or start mysql database (you rarely should need doing that 'by hand'), use proper init script with stop or start parameter, usually /etc/init.d/mysql stop. This, however depends on your linux distribution. Some new distributions encourage service mysql start style.

    3. You're logging in by using mysql sql shell.

    4. The error comes probably because double '-p' parameter. You can provide -ppassword or just -p and you'll be asked for password interactively. Also note, that some instalations might use mysql (not root) user as an administrative user. Check your sqlyog configuration to obtain working connection parameters.

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

    I assume you are looking to use mysql client, which is a good thing and much more efficient to use than any phpMyAdmin alternatives.

    The proper way to log in with the commandline client is by typing:

    mysql -u username -p
    

    Notice I did not type the password. Doing so would of made the password visible on screen, that is not good in multi-user environnment!

    After typing this hit enter key, mysql will ask you for your password.

    Once logged in, of course you will need:

    use databaseName;
    

    to do anything.

    Good-luck.

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

    To stop or start mysql on most linux systems the following should work:

    /etc/init.d/mysqld stop
    
    /etc/init.d/mysqld start
    

    The other answers look good for accessing the mysql client from the command line.

    Good luck!

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

    if you're already logged in as root just

    mysql -u root
    

    prompting the password will otherwise return as error

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

    use this "mysql -uroot -pPassword"

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

    Try "sudo mysql -u root -p" please.

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