 Thank you for staying 20 minutes to write a MySQL shell plugin and you will see I don't even need that that much I guess So who knows my who never heard about MySQL shell? Never? Oh, good. You should The MySQL shell? Yeah, but here is MySQL shell. So unfortunately, I won't talk too much about the shell, right? But I will show you how it works because I was expecting that a lot of people knew MySQL shell If you want to know much more about MySQL shell, I wrote a lot of stuff on my blog and I'm from Belgium So I'm used to the Belgium water that you all had last night. So that's why I'm still up at the end of the day So writing a plugin To write a plugin there are some steps that we need to think about and The first one is the most complicated for me. I guess it's the idea what should my plugin do, right and Most of the plug-in I'm sharing on GitHub are because People are asking questions on the MySQL community Slack on the MySQL forums or at the events And then they say, oh, I'm trying to do this on and I'm not I don't know how to do it Then I say, oh, yeah, I make a shell to make it easy for you then When you have an idea, so I will Create this plug-in you need to find the programming language So after that you need to define a file structure that I will show you then writing the code Which is not that complicated, I guess and then testing it Test techniques can be so more complicated when you integrate multiple stuff in your in your shell plugin for example, I have shell plugin that shows that interact directly with the MySQL router or Shell plugins that configure ProxiesQL that we heard about earlier today So we can do a lot of stuff with the shell. So the idea This is the most complicated part. So I was thinking what could I show and that won't take me ages to code for For the event. So our plugin will take a variable. So as a As an entry right as an argument and it will display all the information about that because maybe as you know We keep some information about variables and that are possible to find in the In performance schema. So we're gonna we're gonna play like that. This is the idea for today Then the language I'm a very poor JavaScript guy My friends knowing JavaScript told me it's because I'm too old that I don't get it but I'm not don't get it. So I'm not able to write anything in JavaScript all this mode asynchronous mode I'm still, you know, I learned cobalt at school. So sorry guys Yeah, do you know you have a script now you're sick mind you think you know it, right? Yeah Yeah Java is not familiar, right? So so I choose Python, right? So this is JavaScript still a mystery for me. Let's go write it in Python I think it's easy and I like the Python dev room. So they are my friends. So I will do it in Python Three sorry, I'm not that old So the plugin we need to To put it in the our user home directory dot my school s H Then plug in and then the extension there. So this is where it should be located and this is the files we need to have In it to create a to underscore the score in it underscore resort PI mostly empty This is just to make our object Then my school s H plug-in common You should not write it. I will provide it to you and I use the same for every time for every every plug-in It's just registration and stuff like that then Usually I use a directory to put my older code that will be related to my plug-in But it can be owns only one file, but I like to use our one directory So I will call it for them then inside again this in it to say to be able to make a An instance of this object then a real in it dot PI with some code in it registration of the variables and The methods and then some files and I will call it variables because this is what we're gonna use today, right? So the first one it's an empty file very easy to do. I think everybody can do it the other one Yeah, it will You can find it on github Or you can copy it Let's see. I will show you what's here. What's in it? And it has the all the registration of the plug-in for the shell So you don't need to do that every time you call the shell, right? Then the code of our plug-in in it file again always empty so again something very easy to do and then the method registration so all the method you're gonna create in the in the real called we need to Registrate Because which is very something very nice with the plug-in infrastructure of the shell is that it will create for example all the help for me So I don't need to write all that so as soon as I will register my methods It will create the help and I will show you how it works So after other than that we just need to code, right? So let's go together. This is a live demo. I Already know Kenny will say oh, this is why it takes 20 minutes because I'm very slow to write On my keyboard for them But let's let's try it. We're gonna do it. No worries Can you read it seems all right? So the first thing I just said was to have the to download the My school is each plug-in common I don't really earlier my machine because the network where I was not able to use the Wi-Fi here So you go in my school a sage dot plug-in Slash plug-in so I mean in directory empty one right and I will create also here up my extension folder and the name of the plug-in we're gonna create today Okay, for that Then we will go in the extension here you do the way get to get the file, but I will copy it from my own directory Mass Qlsh Yeah, I hope you are developer and the it's a developer conference So I wanted to make a bit more You know some code because we haven't discussed a lot of code today already still right So here's the file. Let's have a look. What's in it? So it register the plugins that you're gonna create and this is all the information about the type So it has just this method about the registration and some help and That's it. So it just do the registration of the of your of your object in the So of the plug-in in the shell so after that remember We go in Yeah, I forgot we also need a very complicated file. I hope you will be able to follow This one empty done that was easy This is just pure Python stuff done easy. So now we're gonna create Our init file For our our module itself right for the plug-in we are creating so of course we can We can create whatever we want here. I Always give the name and then some comment, but we won't do that So we need to call my spell s h Plug-ins Come on We're gonna import the registration of the plug-in register Plug-in right and Because I know it because I already tried it you would you will also call import some of the Functions that you and of the old the the elements you're gonna do so usually you do that after when you create it But for a gain of time so I will go in my In my object So in my plug-in first them and I want to import Variables so it's a method inside And I will call it variables plug Okay, and then we register everything This is where the magic happens Because we can give a name usually Even if I write Python when I register my plug-in I always use the Thank you the JavaScript notation notation notation because this is easy and After that I don't care if I call because all the plug-ins that you created you can create them as if it was You can call them as it was JavaScript or Python all the Framework will abstract that for you So if you create everything in Python and then you call every you use everything in JavaScript It will work and this is what I usually do I will copy paste because I'm very slow and We're gonna discuss what I've done and also it will that's it Even for copy pasting and back You So what I'm doing here Some information so here I will say okay. I will call this Module I've created and then I will call that method the method It's get the variable info and we're gonna create it together after Some information about it some parameters one only which is I will call it variable What it is so give some information about what type is it is it required because sometimes you can say oh I want Parameters, but maybe I'm not needed. So you can't say it's not required and Then the full plug-in information the plug-in is called fuzz them and what it does. That's it So this is just in the in it. So not complicated. Just register it all the methods So now the real code will be in our variable So here is where we're gonna create the code So first thing to do We just import my school SH so my school shell module to be able to make all the course we need then we create our Our method the only method we're gonna use in this plug-in which is Get variables info The parameters we have we give and some session if we want to add but usually we don't We leave it at none and if there is we check here because we get from the go global shell if we are connected to a To a my score server we're gonna use that connection to do it if not We can we could create one but here is we use the one we are created and if not it will complain I will not create one in my in my plug-in, but it's possible that you could do that if you want When you have created that The magic let's call it like that or the only code complicated in this case. It's the query So I want to find that information for information schema, right and then play with The output and show it to the to the people and Then it's just some Python Processing this information, right? So what we do? So we do the SQL we check if we got some information We can also use white cart So if I'm searching for some variable with a work hard name He will say oh I found at least three variables that match the query you are looking for and then for each of them I'm looking if These are the default when it's compiled are they being changed by the session are they being changed as a global? Are then being persisted because when my school aid you can persist variable without modifying the my cnf all that information We can see it and that's it and the plug-in is created very so very small files and Yeah, you don't see maybe at the end and Not nothing else every time I will run the shell Right So let's connect to my machine You see so yeah Let's see. Can you see at the back here? So I'm connected to my machine if you have some error here like you make a Syntax error type of you will have an error message that tells you thank you That tells you that you need to check in the error lock of the law of the main school shell It shows you where it is to find what's going on because you may have Created some syntax error or whatever so I wrote the shell my plug-in in Python like I said, right, but I can also call it You see yeah, you don't see because let's see if I can make it I will make it shorter here if I find my mouse So it will be better for you so extension the tab it says first them tab the The method I have for it which are get variables or help I can also do this and It gives me that info. I am in JavaScript. I can go in Python and call Exactly the same way And now you can see the information the the call here the syntax of the name of the function It's not exactly the same because it takes the default Python syntax, right? So let's try to see what what happens to that so first with the help it gives me Oh, you have a plug-in now. This is all the plug-ins I had on the machine I did the test and you have also the first them demo test Then for first them itself you can have a help again You don't have to code that all the framework the my square shell framework give you that and Then you have information also for all the methods that you have in your plug-in and when we test it so I want to test default find the variable called default with the The wild card and plug-in if on one variable it gives you the name and he says okay This was my square native password and it's global and it was set in ETC my CNF So this is the information that you got from this plug-in Another one bin lock format. He said okay. I found one variable. The name is bin lock format the role It's set to roll. It has been persisted Where is it persisted you have the file and as it is was persisted it tells you also, okay It's rude that look at lost that the 12th of April did that persist information so the shell it's very nice to use the shell for DBAs or junior DBAs so the senior DBA can create Plenty of function plenty of plugins to help the junior DBA to do their job easily without Because here it's a very easy one to show you in a very little amount of time, but you can do that Much more complicated to find and I have a plenty of them to Already available and pull requests are welcome or so, but I will show you after the github 3 So when there is multiple variables it also works like that and it gives you every time What's the value if it was the default value if it was compiled or not you will get all that information So the pull requests are welcome Pull requests or feature request because I like I said the most complicated for me was the ID So if you have ideas to improve the shell just let me know put it there and Thank you. That's it for me I really invite you to go check that to be a github repo because we will see very Cool plugins that took more than 20 minutes to write That can be very useful Thank you. Yeah, don't go away. I will give the goodies too late