[Bukkit guide] MySQL

Discussion in 'Bukkit Help' started by zipron, Dec 18, 2011.

Thread Status:
Not open for further replies.
  1. [Bukkit guide] MySQL

    So here we are again this time with a short guide about MySQL. Feedback and likes are always appreciated =)

    Table of contents
    - MySQL? WTF??
    - Setting up a server
    - Endings
    - Useful links


    MySQL? WTF??
    So there are some plugins wich need a database to work with. Some support flatfiles, some support other database types. If a plugin really needs a database, the chance it is a MySQL database is big. MySQL (SQL = structured query language) is a way of hosting databases. It is very powerfull and that is also the reason some plugins want to use it. In this guide I will only cover the installation of the server on linux and windows and I will show you how to config things right so your plugins can work with your MySQL server.

    Setting up a server
    So first thing you'll need to do is downloading the server software. For Linux (ubuntu), you can use this easy command:
    Code (Text):
    1. sudo apt-get install mysql-server
    Follow the instructions given in the instalation. At a point, it will ask for a root password. This is an important password, so be sure you remember it!

    For Windows you'll have to download the MySQL server software from the MySQL site, you'll have to create an account on the site to download the software:
    http://www.mysql.com/downloads/mysql/
    Run through the installation wizard. Press next (and choose deailted configuration) untill it asks for security settings. Here you'll have to choose a root password, same as the linux users: don't forget this! When all is installed, your server is ready to use.

    So what we now have to do is allowing the connection between the bukkit and MySQL server and (if you want that) allowing remote access from other computers.

    In Linux you can start your MySQL server by using this command:
    Code (Text):
    1.  
    2. sudo /etc/init.d/mysql start
    3.  
    If you have ubuntu server installed, MySQL will start up automatically so you won't have to start it. Use this command to start your commandline:
    Code (Text):
    1.  
    2. mysql -u root -p
    3.  
    After this you'll have to give a password. This is the password you filled in in the installation file!

    Windows users will have to go to start > programs > MySQL > MySQL server > MySQL command line
    When your server is started, it will ask for a password. This is the password you filled in in the installation file!

    When this is done, you are logged in as the root user of your server. Now we have to make a user for bukkit and allow it to access the databases. Using following code will create a user with a password. Be sure to change "password1" into the password you want and you can choose another name if you want to.
    Code (Text):
    1. CREATE USER bukkit IDENTIFIED BY 'password1';
    2.  
    3. output:
    4. mysql> CREATE USER bukkit IDENTIFIED BY 'password1';
    5. Query OK, 0 rows affected (0.00 sec)
    6.  
    Now we want this user 'bukkit' being able to access the database. We can bind the user to a certain IP adress. Normally, your MySQL server is on the same machine as your bukkit server wich means we can use the localhost adress: 127.0.0.1. If not, you can grant access from all IP's or grant access to a certain IP. This will mean your plugins can only enter the database if they have that IP adress.
    Localhost:
    Code (Text):
    1.  
    2. GRANT ALL ON *.* TO bukkit@'127.0.0.1';
    3.  
    4. output:
    5. mysql> GRANT ALL ON *.* TO bukkit@'127.0.0.1';
    6. Query OK, 0 rows affected (0.00 sec)
    7.  
    All IP's:
    Code (Text):
    1.  
    2. GRANT ALL ON *.* TO bukkit@'%';
    3.  
    4. output:
    5. mysql> GRANT ALL ON *.* TO bukkit@'%';
    6. Query OK, 0 rows affected (0.00 sec)
    7.  
    Binding an IP adress:
    Code (Text):
    1.  
    2. GRANT ALL ON *.* TO bukkit@'<ipadress>';
    3.  
    4. output:
    5. mysql> GRANT ALL ON *.* TO bukkit@'<ipadress>';
    6. Query OK, 0 rows affected (0.00 sec)
    7.  
    Now restart MySQL to make this changes work: on Windows just restart. On Linux enter following command:
    Code (Text):
    1.  
    2. sudo /etc/init.d/mysql restart
    3.  
    Now the user 'bukkit' can access all databases. If you're on Linux, we have to do one more thing: we have to go to the MySQL config file and change the "bind-adress" property if you want to be able to access the MySQL server from another computer. This is only needed if your MySQL server is on another server than the bukkit one is. So if that is goto
    Code (Text):
    1. zipron@zipronServer:~$ cd /etc/mysql/
    2. zipron@zipronServer:/etc/mysql$ nano my.cnf
    Now search for:
    Code (Text):
    1.  
    2. bind-address          = <ipadress>
    3.  
    and change it to:
    Code (Text):
    1.  
    2. # bind-address          = <ipadress>
    3.  
    Again, you only need to do this if your bukkit server is on another host then you are, or if you want remote access from another computer in your database.

    Now a few more things:
    - if you want remote access, you'll need to port-forward the MySQL port. (3306 by default)
    - The plugins using a database will ask for a host, a user and a password. We create a user and a password in the section above. The host is the IP adress the MySQL server is on. If it's on the same server, you can use the localhost adress: 127.0.0.1. Otherwise you'll need the IP of the MySQL server.

    Endings
    I hope this helped some people out. I made this guide because I saw someone having issues with MySQL and maybe some others can use it too. Now before ending I want to mention that no guide is 100% reliable and correct. So if you see any mistakes, please point them out, me and everyone who uses this guide will be thankfull =)

    Useful links:
    MySQL download page: http://www.mysql.com/downloads/
    MySQL manuel: http://dev.mysql.com/doc/refman/5.1/en/index.html

    that's it, have fun =)
    zip
     
  2. Offline

    Karlkorv

    No Mac? Aww...
     
  3. No I'm anti-mac, sorry =)
    zip
     
  4. Offline

    akaBruce

    Thanks zipron! One small question...Do I portforward both TCP and UDP of the port 3306? (Which I have already done) Also, do I create a database by typing CREATE DATABASE minecraft;?
     
  5. Yes on both questions :)
    zip
     
  6. Offline

    essjaysammy

    Gah I'm an idiot because i can't work this out..
    Can i 'please' ask you for help.. :)
    I want to setup OwnBlocksX plugin which requires MySQL.
    Maybe I'm entering it in wrong, idk.
    I've downloaded MySQL v5.5 and installed it per your instructions.
    I'm entering the right thing I'm assuming, but i get back errors.
    I'm sure it's me.. lol

    I'm running Windows7 64bit and the server is run from my pc.
    Thank's in advance for any help you might be able to give me.
     
  7. Can you copy-paste the errors in here? =)
     
  8. Offline

    chilldy

    Thanks for this. Bookmarked as people ask for this all the time!
     
  9. =) question: what does bookmarked means? xD
     
  10. Offline

    essjaysammy

    Thank's zipron, ill get those errors to you shortly.. Not at home.
     
  11. Offline

    chilldy

    :confused: It means that I saved this page under shortcuts so I can use it as a reference in the future.
     
  12. I see, ok =)
     
  13. Offline

    mmorton89

    quick question does it matter if the SQL database is on the same machine as the server or should I put it on my home machine? my server is on a dedicated service. Would it be better to use my home computer or the dedicated server?
     
  14. consider this:
    If you want it to be on your home computer, you can. Just use the correct IP, username and password, grant privileges on all IPs, or your server IP, open the correct port and it'll work. Now the problem is that your pc has to be online always, witht he MySQL server running. Yes it is possible, and it isn't very good.

    What you can do (if your MC dedicated server doesn't support MySQL): search a webhost wich allows MySQL access (there are free services out there, I think of 000webs as example now). Configure it correctly and it'll work. Now also know that hosting your database in an extern place, isn't the best way of doing things, because it will ask more bandwith usage and it will slow the communication between the server and the database. Now this is ofcourse not the biggest issue, but in my opinion, best thing you can do is hosting it on the same machine as your dedicated server (ask your host about the possibilities)

    zip
     
  15. Offline

    orangemars2000

    Help!
    Firstly, when i downloaded, it didn't ask for root password.
    Then when I tried to open it, it closed itself, kinda like java.
    Help me! what am i doing wrong?!
     
  16. If you installed it, it asked for a root password, if it closes, it means that you fill in the wrong password. So if you don't remember, you can search for the config file (program files > MySQL > somewhere here) and change your password there, or reinstall MySQL

    zip =)
     
  17. Offline

    orangemars2000

    Ah, i found the problem!
    Tell Windows users to donload the FTP one, not HTTP
     
  18. Offline

    orangemars2000

    Now it's saying I have an error in my SQL syntax, when i try to put in the first code?
     
  19. make sure alwyas to use ; after a statement =)
     
  20. Offline

    orangemars2000

    Ok, I have that fixed, but do i always use 127.0.0.1.?
    Or do I use the IP of my server (that other people use)?
    Or my IPv4?
    Probably stupid question though.
     
  21. you have several options, but if your MySQL server is hosted on the same machine as your bukkit server, you use 127.0.0.1 =) if hosted on another place (not reccomanded) you'll have to use the IP of that host

    zip
     
  22. Offline

    Wendo

    One warning, port forwarding to MySQL is a risk. Don't do it unless you absolutely can't live without remote access to this database. You're better off connecting to the server via SSH or some other remote access than trying to remote access directly into MySQL.
     
  23. Why is this? I thought MySQL is quite secure.
     
  24. Offline

    Wendo

    It is, that doesn't mean that most people allow root to log in from any ip and use the password password.

    In 99% of occasions, there is no reason to have a database exposed to the internet since all the servers that actually use it are on the same local network.

    Not to mention, most people that follow this, won't know to keep up to date with MySQL releases and security updates
     
  25. As I mentioned in my tutorial, in Linux you'll have to make another account, by default (the linux version of MySQL) doesn't allow root access from remote connections, so that isn't a problem. I don't know how it is in windows though

    zip =)
     
  26. Offline

    orangemars2000

    I'm back with moar errors D:
    when i type in:
    GRANT ALL ON *.* TO bukkit@'127.0.0.1';
    I get:
    Can't find any matching row in the user table
     
  27. That means you haven't create the user bukkit, or something went wrong when you did. When you're in your MySQL console try this:
    Code (Text):
    1.  
    2. SELECT user FROM mysql.user;
    3.  
    which should give you a list of all users, check if bukkit is there =)
    zip
     
  28. Offline

    mdo13

    You know, there is a mac version too. Same link for windows.
     
  29. I don't have any expierience with mac, so I don't put it in this guide
    zip
     
  30. it should ask a root password, otherwise it means that you've installed it incorrectly, are you sure you hadn't an earlier version installed?
     
Thread Status:
Not open for further replies.

Share This Page