Trang 1/2 12 CuốiCuối
Hiện kết quả từ 1 tới 10 của 11

Chủ đề: Các lệnh quản lý MYSQL qua SSH

  1. #1
    Administrator Rìu Vàng Đôi Rìu Vàng Đôi Avatar của Manhhung
    Tham gia ngày
    Sep 2011
    Bài gửi
    1.472
    Likes received
    217
    Likes given
    17
    Thanks
    55
    Thanked 1.247 Times in 353 Posts

    Các lệnh quản lý MYSQL qua SSH

    How to Delete a MySQL Database via the Terminal


    First, fire up MySQL in your terminal and login as an administrator account with:


    Mã:
    mysql -u root -p

    You will be prompted for your root password before being granted access to the MySQL monitor.

    Now to grab a list of available databases on the system. Running:

    Mã:
    SHOW DATABASES;
    Will result in quite a list of available databases being drawn on the screen (note, it only lists the databases your user account has privileges to see). Once you have located the database you wish to delete in this list we can proceed:

    Mã:
    DROP DATABASE IF EXISTS mydatabase;
    This will now delete the mydatabase database from the MySQL server if it exists. If not, the drop database statement is simply ignored.


    Creating a MySql database and username



    To create a user account from a MySQL server instance, we need to make use of a CREATE USER call to the mysql.user table.
    First, fire up MySQL in your terminal and login as an administrator account with:
    Mã:
    
    mysql -u root -p
    
    You will be prompted for your root password before being granted access to the MySQL monitor.
    Now to grab a list of available user accounts on the system. Running:
    Mã:
    
    SELECT USER,host FROM mysql.USER;
    
    If the user account that you wish to create doesn’t appear in that list, you are good to go. To create a new user account run the following query:
    Mã:
    
    CREATE USER 'daivietp'@'localhost' IDENTIFIED BY 'password-for-new-account';
    
    If you omit the @’localhost’ section, the user account will be generated with a host value of ‘%’. If you omit the identified by section, the user account will be created without a password (which is of course quite insecure).
    Of course, this user isn’t linked to any databases yet, but this is simple to rectify with a:
    Mã:
    
    GRANT ALL ON mydatabase.* TO useraccount@localhost
    

    Create the database

    It is time to actually create the database you will be using for your website. To do this, first choose a good name (we'll use the name gallery as an example), and type:

    create database daivietp_vbb;
    …and press enter. You will then see the following appear:

    Query OK, 1 row affected (0.16 sec)
    This is good, and confirms that the database has been added.

    Create a database user and password

    Now, create a username and a password for your new database. The password should be very secure.

    Let's say that the username will be 'ryan' and the password will be 'GanD1do'. You will then type the following:

    grant all privileges on daivietp_vbb.* to 'daivietp'@'localhost' identified by "GanD1do";

  2. Có 2 bạn gửi cám ơn đến Manhhung trong bài này:


  3. #2
    Rìu Chiến Vàng Chấm Rìu Chiến Vàng Chấm Avatar của Nhonha
    Tham gia ngày
    Nov 2010
    Đến từ
    PHÚ TÂN - AN GIANG - VIỆT NAM
    Tuổi
    20
    Bài gửi
    10.535
    Likes received
    25
    Likes given
    1
    Thanks
    102
    Thanked 1.618 Times in 811 Posts
    Mã:
    GRANT ALL ON  mydatabase .* TO  useraccount@localhost
    dùng cho phần nào thế anh !

  4. #3
    Administrator Rìu Vàng Đôi Rìu Vàng Đôi Avatar của Manhhung
    Tham gia ngày
    Sep 2011
    Bài gửi
    1.472
    Likes received
    217
    Likes given
    17
    Thanks
    55
    Thanked 1.247 Times in 353 Posts
    How to Show MySQL User Accounts via the Terminal
    Hiển thị user

    To get a list of user accounts on a MySQL server instance, we need to make a SELECT call to the mysql.user table.
    First, fire up MySQL in your terminal and login as an administrator account with:
    Mã:
    
    mysql -u root -p
    
    You will be prompted for your root password before being granted access to the MySQL monitor.
    Now to grab a list of available user accounts on the system. Running:
    Mã:
    
    SELECT * FROM mysql.USER;
    
    Will result in quite a big table being attempted to be drawn to the screen. To narrow this down and focus our user listing to just the column information we’re actually interested in, we can run
    Mã:
    
    DESC mysql.USER;
    
    to give us an indication of what columns are available in the system user table. For the most part, we are only really interested in the user account name and accepted host values, meaning our new statement to list the user accounts via the terminal looks as follows:
    Mã:
    
    SELECT USER, host FROM mysql.USER
    

  5. #4
    Administrator Rìu Vàng Đôi Rìu Vàng Đôi Avatar của Manhhung
    Tham gia ngày
    Sep 2011
    Bài gửi
    1.472
    Likes received
    217
    Likes given
    17
    Thanks
    55
    Thanked 1.247 Times in 353 Posts
    Quote Nguyên văn bởi Nhonha Xem bài viết
    Mã:
    GRANT ALL ON  mydatabase .* TO  useraccount@localhost
    dùng cho phần nào thế anh !
    Dùng Tunnelier hoặc Putty đó em , search nhé

  6. #5
    Rìu Chiến Vàng Chấm Rìu Chiến Vàng Chấm Avatar của Nhonha
    Tham gia ngày
    Nov 2010
    Đến từ
    PHÚ TÂN - AN GIANG - VIỆT NAM
    Tuổi
    20
    Bài gửi
    10.535
    Likes received
    25
    Likes given
    1
    Thanks
    102
    Thanked 1.618 Times in 811 Posts
    Em có cái ebook pdf dạng này để up lên cho anh em dvpd

  7. #6
    Administrator Rìu Vàng Đôi Rìu Vàng Đôi Avatar của Manhhung
    Tham gia ngày
    Sep 2011
    Bài gửi
    1.472
    Likes received
    217
    Likes given
    17
    Thanks
    55
    Thanked 1.247 Times in 353 Posts
    How to Set MySQL root Password

    One of the most important things you need to do when setting up your new MySQL server instance is to set the password for the root user account. By default, root has no password which is of course quite the security dilemma.
    The simplest way to set the root password, or indeed any other user account password, is to make use of the bundled mysqladmin.exe application (found in the bin folder of your MySQL installation directory).
    To use, simply open up your command line window and run:
    Mã:
    mysqladmin -u root password newpassword
    where newpassword is your selected password you wish to apply to the root account.
    However, if you already have a password associated with the root account, you then need to add the existing password into the mix, meaning that your application call signature will now look like this:
    Mã:
    mysqladmin -u root -poldpassword newpassword
    (NOTE: this method applies to any user account, so for example to set the password for the user account craig, I would simply input -u craig instead of -u root in my argument list. Oh, and also notice the lack of a space between the -p switch and the supplied password. I have honestly no idea why this is the case, but it does seem like you need to input it in this fashion.)

  8. #7
    Administrator Rìu Vàng Đôi Rìu Vàng Đôi Avatar của Manhhung
    Tham gia ngày
    Sep 2011
    Bài gửi
    1.472
    Likes received
    217
    Likes given
    17
    Thanks
    55
    Thanked 1.247 Times in 353 Posts
    Bài viết hướng dẫn cách backup và restore mysql database sử dụng SSH và Telnet, rất hữu ích với những dữ liệu lớn.

    Phần đầu tiên là mình xin hướng dẫn cách sao lưu cơ sở dữ liệu...

    I/ BACK UP:
    Đầu tiên để thực hiện việc back up data bạn cần 2 thứ sau:
    1/ Bạn nên xem Host bạn có hỗ trợ SSH và Telnet không, việc này bạn cần xem lại nhà cung cấp dịch vụ của bạn.
    2/ Một SSH hoặc Telnet Client như là PuTTy (cái này bạn tìm trên Google có rất nhiều):
    Sau đó bạn mở chương trình đó lên và login vào website của bạn.Các dòng lệnh nhắc bạn sẽ nhìn thấy sẽ khác nhau của hệ điều hành.
    Đối với hầu hết các công ty Hosting, điều này sẽ đưa bạn vào trong thư mục gốc FTP.
    Gõ vào phần sau đây để tạo một sao lưu trong thư mục hiện hành:
    mysqldump --opt -Q -u dbusername -p databasename > backupname.sql


    Hoặc để tạo một sao lưu trong một thư mục riêng biệt ví dụ như thư mục /path/to/ thì bạn chỉ việc gõ
    mysqldump --opt -Q -u dbusername -p databasename > /path/to/backupname.sql

    Bạn sẽ được nhắc nhở databasa mật khẩu.Bạn hãy điền vào và database sẽ back up..!!!
    Nếu công ty hosting của bạn xài trên một máy chủ MySQL từ xa (remote Mysql), như mysql.yourhost.com, bạn sẽ cần phải thêm servername vào dòng lệnh. Các servername sẽ được giống như trong config.php. Các dòng lệnh bạn cần gõ là:
    Thư mục hiện hành:
    mysqldump --opt -Q -h servername -u dbusername -p databasename > backupname.sql

    Thư mục riêng biệt:
    mysqldump --opt -Q -h servername -u dbusername -p databasename > /path/to/backupname.sql

    Sau đó bạn có thể download một bản về máy để đề phòng trường hợp xấu có thể xảy ra...!!!

    Phần hai là phần Restore Database:

    II/ Restore Database thông qua SSH và Telnet:
    Bạn chỉ việc mở chương trình SSH hoặc Telnet Client và bạn login vào Website của bạn, ở đây các bạn chú ý là phải upload file data các bạn cần restore lên Host. Nếu file back up các bạn upload lên root folder thì các bạn gõ dòng lệnh sau:
    mysql -u dbusername -p databasename < backupname.sql

    Nếu file back up nằm ở folder khác thì bạn gõ:
    mysql -u dbusername -p databasename < /path/to/backupname.sql

    Sau đó nó sẽ hỏi bạn mật khẩu của database của data mà bạn cần restore, bạn chỉ việc gõ vào là Ok..DONE..!!!
    Các bạn chú ý là ở trên đây: dbusername,databasename , database password là những thông số về data mới mà bạn cần restore...!!!
    Nếu công ty hosting của bạn xài trên một máy chủ MySQL từ xa (remote Mysql), như mysql.yourhost.com, bạn sẽ cần phải thêm servername vào dòng lệnh. Các servername sẽ được giống như trong config.php. Các dòng lệnh bạn cần gõ là:
    Thư mục hiện hành:
    mysql -h servername -u dbusername -p databasename < backupname.sql

    Thư mục riêng biệt:
    mysql -h servername -u dbusername -p databasename < /path/to/backupname.sql
    Vậy là xong...!!!!

    Note:
    Nếu là người quản lý server, các bạn có thể dùng user root của MySQL để thay thế cho bất cứ user bình thường nào khi backup hay restore 1 database bất kỳ trên server.
    Các bạn cần phải biết và nhớ password của MySQL root user vì password này không phải là pass root của server.

    Chúc các bạn thành công...!!!!

  9. #8
    Administrator Rìu Vàng Đôi Rìu Vàng Đôi Avatar của Manhhung
    Tham gia ngày
    Sep 2011
    Bài gửi
    1.472
    Likes received
    217
    Likes given
    17
    Thanks
    55
    Thanked 1.247 Times in 353 Posts
    Backing up using SSH

    Note: Some hosts do not offer SSH access, I suggest contacting your host and asking him/her if SSH access is enabled and if so the details. A good program to use for connecting via SSH is PuTTY (Get it at: http://www.chiark.greenend.org.uk/~sgtatham/putty/). Don't know how to use it? Search on Google for a tutorial.
    1. Connect to your host via SSH, login and run:
      Mã:
      mysqldump --opt -u user -p dbname > {path}/backup.sql
    2. You will be asked to type out your password once you run that command, do so and click enter. It may take some time for it to respond, but once completed you should be brought back to where you started (bash/command line).
    Congratulations! You successfully backed up your database using SSH.

    Restoring using SSH

    Note: Some hosts do not offer SSH access, I suggest contacting your host and asking him/her if SSH access is enabled and if so the details. A good program to use for connecting via SSH is PuTTY (Get it at: http://www.chiark.greenend.org.uk/~sgtatham/putty/). Don't know how to use it? Search on Google for a tutorial.
    1. Connect to your host via SSH, login & run:
      Mã:
      mysql -u user -p dbname < {path}/backup.sql
    2. You will be asked to type out your password once you run that command, do so and click enter. It may take some time for it to respond, but once completed you should be brought back to where you started (bash/command line).
    Congratulations! You have successfully restored your database using SSH.

    That's basically it I think, I believe I have covered everything? Anything I missed? Comments or suggestions? Just let me know! Hope this tutorial was as useful to you as it is to me.

    Thanks,

  10. #9
    Rìu Chiến Vàng Chấm Rìu Chiến Vàng Chấm Avatar của Nhonha
    Tham gia ngày
    Nov 2010
    Đến từ
    PHÚ TÂN - AN GIANG - VIỆT NAM
    Tuổi
    20
    Bài gửi
    10.535
    Likes received
    25
    Likes given
    1
    Thanks
    102
    Thanked 1.618 Times in 811 Posts
    Ở Ngoàh có 2 con Bot đang spam chìm gủm topic http://daivietpda.com/sach-va-tai-li...tml#post282824

  11. #10
    Rìu Sắt Rìu Sắt
    Tham gia ngày
    May 2011
    Bài gửi
    149
    Likes received
    0
    Likes given
    0
    Thanks
    43
    Thanked 6 Times in 1 Post

    Re: Các lệnh quản lý MYSQL qua SSH

    Sao anh ko dung goole dich ra cho anh em dvpd hieu '

Trang 1/2 12 CuốiCuối

Thông tin chủ đề

Users Browsing this Thread

Hiện có 1 người đọc bài này. (0 thành viên và 1 khách)

Chủ đề tương tự

  1. help mysql
    Gửi bởi k3ng1991 trong mục Kiến thức lập trình
    Trả lời: 0
    Bài cuối: 16-09-2011, 10:42 AM
  2. [HELP]Ai prồ về MySQL cho hỏi lỗi này với!
    Gửi bởi Arituan trong mục Kiến thức lập trình
    Trả lời: 10
    Bài cuối: 14-09-2011, 07:18 PM
  3. MySQL Là Gì ?
    Gửi bởi lovevn trong mục Kiến thức lập trình
    Trả lời: 2
    Bài cuối: 03-07-2011, 08:52 PM
  4. [help] php và mysql
    Gửi bởi gacon trong mục Kiến thức lập trình
    Trả lời: 0
    Bài cuối: 19-02-2011, 12:43 AM
  5. [Help] Mysql cua host1free.com
    Gửi bởi bluesky trong mục Hosting / Domain
    Trả lời: 1
    Bài cuối: 07-10-2010, 03:22 PM

Từ khóa (Tag) của chủ đề này

Đánh dấu

Quyền viết bài

  • Bạn không thể gửi chủ đề mới
  • Bạn không thể gửi trả lời
  • Bạn không thể gửi file đính kèm
  • Bạn không thể sửa bài viết của mình
  •  
  • Game gomobi | Ongame Mobi 222 | iWin 247 | Game iWin Online | Mobi army 205|